我正在编写菜单代码,这次使用 CSS 制作动画,并使用 js 将类从显示更改为隐藏和半隐藏。 (js还没入手)
有些问题我不知道如何解决(压力很大)。
- 为什么上边距不是 0?
- 为什么在 div 之间的左侧和顶部有一些 padding/margin/wtv?
- 如何使链接垂直居中? (我认为我需要继续使用 100% 并固定位置并 overflow hidden ,因为我需要将 div 移出屏幕)
html,
body {
background: #E6E6E6;
}
.menu {
overflow: hidden;
position: fixed;
height: 100%;
width: 100%;
-webkit-transition: all ease .65s;
-moz-transition: all ease .65s;
-ms-transition: all ease .65s;
-o-transition: all ease .65s;
transition: all ease .65s;
}
.left {
right: 0;
margin-right: 0;
}
.left.bar {
right: 100%;
margin-right: -60px;
}
.left.hidden {
right: 100%;
margin-right: 0;
}
.menu > .links {
color: white;
font-family: sans-serif;
font-size: 2.5em;
font-weight: 500;
text-align: center;
text-transform: uppercase;
}
.menu li {
color: rgba(255, 255, 255, .75);
cursor: pointer;
list-style: none;
padding: 15px;
margin: 5px;
-webkit-transition: all ease 1s;
-moz-transition: all ease 1s;
-ms-transition: all ease 1s;
-o-transition: all ease 1s;
transition: all ease 1s;
}
.menu li:hover {
color: rgba(255, 255, 255, 1);
background: rgba(0, 0, 0, .1);
}
.m1 {
background: orange;
z-index: 8;
}
<div class="menu left m1">
<div class="links l1">
<ul>
<li data-open=".m2">Architecture</li>
<li data-open=".m3">Coding</li>
<li data-open=".m4">Thesis</li>
</ul>
</div>
</div>
最佳答案
要删除左侧和顶部的空间,您必须覆盖 ul 的默认样式:
ul{
padding: 0;
margin: 0;
}
为了垂直居中,我会这样做:
.links ul{
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.links{
height: 100%;
}
在这里查看:JSFiddle
关于html - 问题居中元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26593652/