我有一個固定的頭部,其中有一個<nav>
。問題是我嘗試了很多東西,但是我的元素不能在中間垂直對齊。我不能使用line-height
,因爲它取決於屏幕分辨率。將NAV垂直對齊到頭部
CSS
header {
width: 100%;
height: 15%;
background-color: rgba(30, 30, 30, 0.75);
color: white;
font-family: 'Roboto', sans-serif;
font-weight: bold;
text-align: center;
position: fixed;
text-transform: uppercase;
overflow: hidden;
}
header nav {
text-align: center;
display: inline-block;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: 0;
}
header nav a {
/*line-height: 6;*/
color: white;
padding: 14px 16px;
text-align: center;
display: inline;
text-decoration: none;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
HTML
<header>
<div>
<nav>
<a class="active" href="">Home</a>
<a href="">News</a>
<a href="">Info</a>
<a href="">Contact</a>
</nav>
</div>
</header>
演示:http://jsfiddle.net/JJ8Jc/4082/
非常感謝你。 – Alex