纯CSS编写面包屑导航栏

说明:本方法使用CSS3,无图片,兼容各种webkit系浏览器,同时兼容IE8+。先上图:

QQ截图20140522145407

1.首先是HTML代码,比较简单,只需要一个简单的ul和li即可

[html]

[/html]

2.接下来是CSS代码,首先是设定常规的li浮动和a标签美化:

[css]
#crumbs ul li {
float: left;
list-style: none;
}
#crumbs ul li a {
display: block;
float: left;
height: 34px;
background: #f66fa2;
text-align: center;
padding: 10px 20px 0 45px;
position: relative;
margin: 0 10px 0 0;
font-size: 20px;
text-decoration: none;
color: #fff;
}
[/css]

接下来就是面包屑导航的关键地方,通过before和after来创建箭头效果:

[css]
#crumbs ul li a:after {
content: “”;
border-top: 22px solid transparent;
border-bottom: 22px solid transparent;
border-left: 22px solid #f66fa2;
position: absolute; right: -22px; top: 0;
z-index: 1;
}
#crumbs ul li a:before {
content: “”;
border-top: 22px solid transparent;
border-bottom: 22px solid transparent;
border-left: 22px solid #fff;
position: absolute; left: 0; top: 0;
}
#crumbs ul li:first-child a {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
padding-left: 40px;
}
#crumbs ul li:first-child a:before {
display: none;
}
#crumbs ul li:last-child a {
padding-right: 30px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
#crumbs ul li:last-child a:after {
display: none;
}
#crumbs ul li a:hover {
background: #e56592;
transition: all 0.2s ease;
}
#crumbs ul li a:hover:after {
border-left-color: #e56592;
transition: all 0.2s ease;
}
[/css]

最后清除浮动:
[css]
.fixed {
clear: both;
}
[/css]



8 thoughts on “纯CSS编写面包屑导航栏

Comments are closed.