怎么设置ul ,li标签元素横排且居中啊?
2个回答
2013-05-26
展开全部
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/html; charset=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>
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=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>
推荐于2016-03-17
展开全部
CSS中定义一下li的修饰li {
list-style-type: none;
display: inline;
}
list-style-type: none;
display: inline;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询