<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul>
其样式表是:
ul{
/*因IE和Opera使用左空白控制列表缩进,而Firefox使用左填充,所以先将margin和padding设置为0*/
margin:0;
padding:0;
list-style-type:none; /*去掉列表前面的符号*/
}
要将锚显示块壮,并不是直接对列表应用样式,而是对其中包含的锚应用样式:
ul{
/*因IE和Opera使用左空白控制列表缩进,而Firefox使用左填充,所以先将margin和padding设置为0*/
margin:0;
padding:0;
list-style-type:none; /*去掉列表前面的符号*/
}
ul a{
display:block;
width:100px;
height:40px;
line-height:40px; /*将行高也设置为40px,是为了让文本垂直居中*/
color:#000;
text-decoration:none;
}
接下来实现颜色和鼠标指向锚时的颜色变化效果:ul a{
display:block;
width:100px;
height:40px;
line-height:40px; /*将行高也设置为40px,是为了让文本垂直居中*/
color:#000;
background:#94b8e9 url(image/pixy-rollover.gif) no-repeat left center;
text-indent:50px; /*锚文本缩进50,是为了不让文字盖子在箭头上*/
text-decoration:none;
}
a:hover{
background-position:right bottom;
color:#fff;
}
仔细看,发现顶边框和底边框形成双重实线,怎么办?采用这样的方法:
ul a{
display:block;
width:200px;
height:39px;
line-height:39px;
color:#000;
background:#94b8e9 url(image/pixy-rollover.gif) no-repeat left bottom;
text-indent:50px;
text-decoration:none; /*锚文本缩进50,是为了不让文字盖子在箭头上*/
}
a:hover{
background-position: right bottom;
color:#fff;
}
虽然没有双重线,但又出现了新的问题:第一项顶部的线也没了,继续:
<ul>
<li class="first"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul>
.......
ul a{
display:block;
width:200px;
height:39px;
line-height:39px;
color:#000;
background:#94b8e9 url(image/pixy-rollover.gif) no-repeat left bottom;
text-indent:50px;
text-decoration:none; /*锚文本缩进50,是为了不让文字盖子在箭头上*/
}
li.first a{
height:40px;
line-height:40px;
}
.......
完整的代码
<!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=utf-8" />
<title>list_shu</title>
<style type="text/css">
<!--
ul{
/*因IE和Opera使用左空白控制列表缩进,而Firefox使用左填充,所以先将margin和padding设置为0*/
margin:0;
padding:0;
list-style-type:none; /*去掉列表前面的符号*/
}
ul a{
display:block;
width:200px;
height:39px;
line-height:39px;
color:#000;
background:#94b8e9 url(image/pixy-rollover.gif) no-repeat left bottom;
text-indent:50px;
text-decoration:none; /*锚文本缩进50,是为了不让文字盖子在箭头上*/
}
li {
display:inline; /*在IE中,列表上下会添加额外的空间,加上它就可以消除*/
}
li.first a{
height:40px;
line-height:40px;
}
a:hover{
background-position: right bottom;
color:#fff;
}
-->
</style>
</head>
<body>
<ul>
<li class="first"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
<!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=utf-8" />
<title>list_shu</title>
<style type="text/css">
<!--
ul{
/*因IE和Opera使用左空白控制列表缩进,而Firefox使用左填充,所以先将margin和padding设置为0*/
margin:0;
padding:0;
list-style-type:none; /*去掉列表前面的符号*/
}
ul a{
display:block;
width:200px;
height:39px;
line-height:39px;
color:#000;
background:#94b8e9 url(image/pixy-rollover.gif) no-repeat left bottom;
text-indent:50px;
text-decoration:none; /*锚文本缩进50,是为了不让文字盖子在箭头上*/
}
li {
display:inline; /*在IE中,列表上下会添加额外的空间,加上它就可以消除*/
}
li.first a{
height:40px;
line-height:40px;
}
a:hover{
background-position: right bottom;
color:#fff;
}
-->
</style>
</head>
<body>
<ul>
<li class="first"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>