CSS教程高級應(yīng)用 2個純CSS面包屑導(dǎo)航欄實現(xiàn)代碼
發(fā)布時間:2014-10-11 16:42:01 作者:佚名
我要評論

這篇文章主要為大家介紹了兩個純CSS 面包屑導(dǎo)航欄實現(xiàn)代碼,內(nèi)容比較簡單,不會的朋友可以進來看一下,其中HTML代碼實現(xiàn)非常簡單,需要的朋友可以參考下
下面是兩個純CSS 面包屑導(dǎo)航欄實現(xiàn)代碼,在網(wǎng)上找了一些方法但覺得都不合適唯獨這兩個純css的就差不多了,下面一聚小編來給大家整理一下。
方法一,
說明:本方法使用CSS3,無圖片,兼容各種webkit系瀏覽器,同時兼容。先上圖:
1.首先是HTML代碼,比較簡單,只需要一個簡單的ul和li即可代碼如下:
復(fù)制代碼
代碼如下:<div id="crumbs">
<ul>
<li><a href="#">首頁</a></li>
<li><a href="#">目錄</a></li>
<li><a href="#">子目錄</a></li>
</ul>
<div class="fixed"></div>
</div>
<ul>
<li><a href="#">首頁</a></li>
<li><a href="#">目錄</a></li>
<li><a href="#">子目錄</a></li>
</ul>
<div class="fixed"></div>
</div>
2.接下來是CSS代碼,首先是設(shè)定常規(guī)的li浮動和a標(biāo)簽美化:
復(fù)制代碼
代碼如下:#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;
}
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;
}
接下來就是面包屑導(dǎo)航的關(guān)鍵地方,通過before和after來創(chuàng)建箭頭效果:
復(fù)制代碼
代碼如下:#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;
}
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;
}
最后清除浮動:
復(fù)制代碼
代碼如下:.fixed {
clear: both;
}
clear: both;
}
方法二:
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.dbjr.com.cn/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.dbjr.com.cn/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset="utf-8″ />
- <title>純css制作面包屑,兼容IE6</title>
- <style type="text/css">
- *{margin:0;padding:0;list-style-type:none;}
- a,img{border:0;}
- body{font:12px/180% Arial, Helvetica, sans-serif, "新宋體";}
- /* demo */
- .demo{width:600px;margin:100px auto;background:#f0f0f0;position:relative;}
- .demo ul{height:32px;overflow:hidden;}
- .demo li{float:left;width:200px;text-align:center;position:relative;z-index:2;font-weight:bold;font-size:14px;line-height:32px;}
- .demo li em{position:absolute;right:-24px;top:-8px;width:0;height:0;line-height:0;border-width:24px 0 24px 24px;border-color:transparent transparent transparent #fff;border-style:dashed dashed dashed solid;}
- .demo li i{position:absolute;right:-16px;top:0;width:0;height:0;line-height:0;border-width:16px 0 16px 16px;border-color:transparent transparent transparent #f0f0f0;border-style:dashed dashed dashed solid;}
- .demo li.current{background:#f60;color:#fff;z-index:1;}
- .demo li.current i{border-color:transparent transparent transparent #f60;}
- </style>
- </head>
- <body>
- <div class="demo">
- <ul class="clearfix">
- <li>面包屑一<em></em><i></i></li>
- <li class="current">面包屑二<em></em><i></i></li>
- <li>面包屑二<em></em><i></i></li>
- </ul>
- </div>
- </body>
- </html>
相關(guān)文章
html+css+js實現(xiàn)導(dǎo)航欄滾動漸變效果
這篇文章主要介紹了html+css+js實現(xiàn)導(dǎo)航欄滾動漸變效果,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-28- 這篇文章主要介紹了純CSS實現(xiàn)導(dǎo)航欄下劃線跟隨效果,本文圖文并茂實例代碼詳解,給大家介紹的非常詳細(xì),需要的朋友參考下吧2019-12-09
- 這篇文章主要介紹了基于html+css 實現(xiàn)簡易導(dǎo)航欄功能,主要就是css(級聯(lián)樣式表)對html的內(nèi)容做格式化。具體內(nèi)容詳情大家跟隨小編一起通過本文學(xué)習(xí)吧2021-04-07
- 這篇文章主要介紹了CSS中的導(dǎo)航欄和下拉菜單的實現(xiàn)的相關(guān)資料,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-18
- 這篇文章主要介紹了純CSS實現(xiàn)導(dǎo)航欄下劃線跟隨滑動效果,需要的朋友可以參考下2018-03-29
- 這篇文章主要介紹了使用CSS制作立體導(dǎo)航欄的相關(guān)資料,需要的朋友可以參考下2017-10-16
div+css實現(xiàn)帶箭頭的面包屑導(dǎo)航欄
本文主要介紹了制作漂亮美觀的帶箭頭的面包屑導(dǎo)航欄的示例代碼。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-06- 本篇文章主要介紹了CSS導(dǎo)航欄及彈窗示例代碼,導(dǎo)航欄和彈窗是在web中應(yīng)用很廣泛的,非常具有實用價值,需要的朋友可以參考下。2017-01-10
- CSS 的強大之處有的時候超乎我們的想象,Tab 切換,常規(guī)而言確實需要用到一定的腳本才能實現(xiàn)。下面看看如何使用純CSS實現(xiàn)導(dǎo)航欄Tab切換效果2016-10-13
- 這篇文章主要介紹了CSS利用偽元素實現(xiàn)導(dǎo)航欄斜線分隔的相關(guān)資料2016-03-14