我正在爲我的菜單編寫代碼,這次使用CSS爲動畫和js將類從顯示更改爲隱藏和半隱藏。 (我還沒有開始在js上)居中元素的問題
一些問題我不知道如何解決(變得非常緊張)。
- 爲什麼頂邊距不是0?
- 爲什麼在div與左邊和頂邊有一些padding/margin/wtv?
- 如何將鏈接垂直居中? (我想我需要使用100%,以保持和位置固定和溢出隱藏,因爲我需要移動的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>
下面的答案是正確的,我只是想強調,利潤/填充是瀏覽器默認樣式的一部分 - 並且還有更多。查看CSS重置 - http://meyerweb.com/eric/tools/css/reset/上最基本的重置。 – 2014-10-27 18:36:18