一float:left
<body>
<ul>
<li>新闻</li>
<li>视频</li>
<li>图片</li>
<li>军事</li>
<li>NBA</li>
<li>体育</li>
<li>新闻</li>
<li>视频</li>
<li>图片</li>
<li>军事</li>
<li>NBA</li>
<li>体育</li>
</ul>
</body>
<style>
*{
padding: 0;
margin: 0;
}
ul{
overflow: hidden;//清除浮动
width: 1230px;
background-color: #0087CC;
margin: 10px auto;
padding-left: 20px;
border-radius: 6px;
color: white;
}
li{
float: left;
list-style: none;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
cursor: pointer;
}
li:hover{
background-color: #02B2FF;
}
</style>
二display:inline-block
<style>
*{
padding: 0;
margin: 0;
}
ul{
width: 1218px;
background-color: #0087CC;
margin: 10px auto;
padding: 0px 30px;
border-radius: 6px;
color: white;
}
li{
display: inline-block;
list-style: none;
width: 97px;
height: 50px;
line-height: 50px;
text-align: center;
cursor: pointer;
}
li:hover{
background-color: #02B2FF;
}
</style>