6.组装链接盒子a,这里用到样式: display: block;让链接以块状方式呈现,并为链接安排背景图片,为了安全起见设置背景不重复,垂直居中(如果浏览器出错解释错误,而你的背景又不是纯色的,那么盒子过大导致的背景重复将会影响网页美观),链接文字样式去除下划线,样式如下:
.lanBoxIn a {
background: url(lanbj2.gif) no-repeat left center;
text-decoration: none;
height: 20px;
width: 155px;
display: block;
float: right;
padding: 0px 0px 0px 5px;
font-weight: bold;
font-size: 9pt;
line-height: 20px;
color: #663300;
}
7.最后简单为鼠标移到链接上时,链接风格的改为指定一个样式:
.lanBoxIn a:hover {
background-image: url(lanbj3.gif);
color: #FFFFFF;
}
至此完成样式代码编写,下面给出内容部分的结构代码,当然我们并不是先把样式代码都写好了再写结构代码的,一般是由外到里,一边写样式一边组织内容结构的,本人只是为了讲解方便而先全部给出样式代码。
像这种列表式导航栏用无序列表(ul/li)来实现更科学,结构代码如下:
<ul class="nav">
<li class="lanList">
<div class="lanBoxIn">
<span></span><a href="#">彻底弄懂CSS盒子模式1</a>
</div>
</li>
<li class="lanList">
<div class="lanBoxIn">
<span></span><a href="#">彻底弄懂CSS盒子模式2</a>
</div>
</li>
<li class="lanList">
<div class="lanBoxIn">
<span></span><a href="#">彻底弄懂CSS盒子模式3</a>
</div>
</li>
<li class="lanList">
<div class="lanBoxIn">
<span></span><a href="#">彻底弄懂CSS盒子模式4</a>
</div>
</li>
<li class="lanList">
<div class="lanBoxIn">
<span></span><a href="#">彻底弄懂CSS盒子模式5</a>
</div>
</li>
</ul>
源文件打包下载 xhtml.rar