核心技術(shù):利用css精靈(主要是背景位置)和盒子padding撐開寬度,以便能適應(yīng)不用字?jǐn)?shù)的導(dǎo)航欄。
1. 使用a設(shè)置背景左側(cè),并用padding-left撐開合適的寬度
2. span設(shè)置背景右側(cè),padding-right撐開合適的寬度,最好和上面的padding-left設(shè)置為同一個(gè)值,以實(shí)現(xiàn)文字左右居中的效果。
3. 使用a標(biāo)簽包含span就是因?yàn)檎麄€(gè)導(dǎo)航都是可以點(diǎn)擊的。
<a class="a">
<span class="span">首頁首頁首頁</span>
</a>
.a {
display: inline-block;
height: 33px; /*不要設(shè)置寬度,寬度是用內(nèi)容撐開的*/
line-height: 33px;
background: url(image/bgi.png) no-repeat;
padding-left: 15px;
color: #fff;
text-decoration: none; /*去除下劃線*/
}
.span {
display: inline-block;
height: 33px;
background: url(image/bgi.png) no-repeat right; /*背景圖像不平鋪,右對齊*/
padding-right: 15px;
}