我需要居中使用無序列表的固定標題nav。中間列表項目留空,因爲我正在放置一個背景圖像。
現在它「看起來」居中,雖然如果你橡皮筋瀏覽器窗口,你可以看到它不是。我可以實現差不多中間的寬度從960px減少到〜780px,但我不想這樣做。
我確定我在這裏忽略了一些簡單的東西。謝謝!
HTML:
<header>
<nav>
<ul>
<li><a class="active" href="#">Home</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Services</a></li>
<li class="logo"></li>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
CSS
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body{
background-color: #ebebeb;
}
nav {
width: 960px;
margin: 0 auto;
}
ul{
list-style-type: none;
text-align: center;
}
li{
display: inline-block;
height: 120px;
float: left;
text-align: center;
line-height: 120px;
margin-right: 30px;
}
.logo {
height: 130px;
width: 164px;
background:url(http://samaradionne.com/img/typeBlack.png) no-repeat;
}
section.stretch{
float: left;
height: 1500px;
width: 100%;
}
header{
width: 100%;
background: #fff;
border-bottom: 1px solid #aaaaaa;
position: fixed;
z-index: 10;
text-align: center;
}
header a{
color: #969696;
text-decoration: none;
font-family: sans-serif;
text-transform: uppercase;
}
看看這個主題/回答:http://stackoverflow.com/a/8228669/1375372 – 2013-04-09 19:10:55
我能夠通過添加「display:inline-block;」來獲得標題中心。到ul元素。 – jennyfofenny 2013-04-09 19:10:55
和另一個線程(必須有數百個)http://stackoverflow.com/a/14511370/1340674 – Pevara 2013-04-09 19:24:22