将ul里面的li标签都设置为右浮动即可。如:
<ul style="overflow:hidden display:block"><li class="float:right padding:10px>项目1</li>
<li class="float:right padding:10px>项目1</li>
<li class="float:right padding:10px>项目1</li>
<li class="float:right padding:10px>项目1</li>
</ul>
li标签元素横排,关键是float属性,比如下例,li往左浮动,不清除浮动即可。居中显示,把ul,li用一个盒子nav装起来,并设置 “text-align: center”属性即可,即内容居中。具体如下例所示 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#nav {
height: 30px
width: 100%
background-color: #c00
text-align: center
}
#nav ul {
margin: 0 0 0 30px
padding: 0px
font-size: 12px
color: #FFF
line-height: 30px
white-space: nowrap
}
#nav li {
list-style-type: none
display: inline
}
#nav li a {
text-decoration: none
font-family: Arial, Helvetica, sans-serif
padding: 7px 10px
color: #FFF
}
#nav li a:hover {
color: #ff0
background-color: #f00
}
</style>
</head><body>
<div id="nav">
<ul>
<li><a href=" http://www.52css.com/">HomePage</li></A>
<li><a href=" http://www.52css.com/">Div+CSS教程</a></li>
<li><a href=" http://www.52css.com/">CSS布局实例</a></li>
<li><a href=" http://www.52css.com/">CSS2.0教程 </a></li>
<li><a href=" http://www.52css.com/">CSS在线手册</a></li>
<li><a href=" http://www.52css.com/">Web标准</a></li>
<li><a href=" http://www.52css.com/">XHTML教程</a></li>
</ul>
</div></body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)