CSS
body {
background-color:#CCC
}
h1 {
text-align: left;
border-bottom:2px solid #03F margin-bottom:50px;
border-bottom: 5px;
border-bottom-color: #000;
border-bottom-style: double;
border-bottom-width: thick;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 72px;
font-style: normal;
font-weight: bold;
-moz-box-align: center;
}
.div1 {
margin-width: 0px auto;
-moz-box-align: center;
-webkit-box-align: center;
margin: center;
margin-left: 150px;
margin-right: 100px;
}
.div1 ul li {
margin:auto;
float: left;
list-style-type: none;
}
.div1 ul li a {
margin:auto;
color: #FFF;
text-decoration: none;
background-color: #333;
display: block;
height: 50px;
width: 220px;
text-align: center;
line-height: 50px;
border-left-width: thin;
border-left-style: solid;
border-left-color: #CCC;
}
.noBorder {
border-left-style: none !important;
}
.div1 ul li a:hover {
background-color: #666;
}
.leftEdge {
border-radius: 8px 0px 0px 8px;
}
.rightEdge {
border-radius: 0px 8px 8px 0px;
}
.divide {
padding: 10px 20px;
background:SkyBlue;
border: 1px solid #E5E5E5;
-moz-box-shadow: rgba(200, 200, 200, 0.7) 0 4px 10px -1px;
-webkit-box-shadow: rgba(200, 200, 200, 0.7) 0 4px 10px -1px;
box-shadow: rgba(200, 200, 200, 0.7) 0 4px 10px -1px;
margin-bottom: 20px;
margin-left:100px;
margin-right:250px;
font-family:"Trebuchet MS", Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 16px;
line-height: 100%;
color: #000;
}
HTML
<h1>hEAD</h1>
<div class="div1">
<ul>
<li><a href="#" class="noBorder leftEdge">Item 1</a>
</li>
<li><a href="#">Item 2</a>
</li>
<li><a href="#">Item 3</a>
</li>
<li><a href="#" class="rightEdge">Item 4</a>
</li>
</ul>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="divide" style="font-weight: normal !important;">Hey friends</div>
任何人都可以帮助我:
我想把我的导航栏放在网页的中心。
这是我的HTML和CSS文档:
http://jsfiddle.net/dQbqP/
请帮帮我,我真的需要解决方案。
尽快
答案 0 :(得分:1)
使用text-align&amp;显示:li的内联块: http://jsfiddle.net/dQbqP/1/
.div1 {
margin:auto;
text-align:center;
}
.div1 ul li {
display:inline-block;
list-style-type: none;
}
答案 1 :(得分:0)
试试这个......
body { background-color:#CCC }
.div1{
text-align:centre;
width:100%;
}
ul{
width:35%;
display:block;
margin:0 auto;
padding:0px;
}
li{
list-style:none;
float:left;
margin:0px;
padding:10px;
background-color: #333;
}
a {
color: #FFF;
text-decoration: none;
}
li:hover { background-color: #666; }
li:first-child { border-radius: 8px 0px 0px 8px; }
li:last-child { border-radius: 0px 8px 8px 0px; }