css制作的立體導(dǎo)航欄,具體實(shí)現(xiàn)代碼如下所示:
<!doctype html><html lang="en"> <head> <meta charset="UTF-8"> <title>CSS制作立體導(dǎo)航</title> <link rel="stylesheet" href="http://www.w3cplus.com/demo/css3/base.css"> <style> body{ background: #ebebeb; } .nav{ width:560px; height: 50px; font:bold 0/50px Arial; text-align:center; margin:40px auto 0; background: #f65f57; /*制作導(dǎo)航圓角*/ border-radius: 8px; /*制作導(dǎo)航立體效果*/ box-shadow: 0 7px 0 #ba4a45; } .nav a{ display: inline-block; /* a元素的過(guò)渡屬性:1、設(shè)置所有a標(biāo)簽過(guò)渡;2、過(guò)渡時(shí)間;3、速度曲線:以慢速開始的過(guò)渡效果 */ -webkit-transition: all 0.2s ease-in;/* Safari 和 Chrome */ -moz-transition: all 0.2s ease-in;/* Firefox */ -o-transition: all 0.2s ease-in;/* Opera */ -ms-transition: all 0.2s ease-in;/* IE 9 */ transition: all 0.2s ease-in; } .nav a:hover{ /* 鼠標(biāo)移上時(shí)的效果;定義2D旋轉(zhuǎn)10度 */ -webkit-transform:rotate(10deg); -moz-transform:rotate(10deg); -o-transform:rotate(10deg); -ms-transform:rotate(10deg); transform:rotate(10deg); } .nav li{ position:relative; display:inline-block; padding:0 16px; font-size: 14px; text-shadow:1px 2px 4px rgba(0,0,0,.5); list-style: none outside none; } /*制作導(dǎo)航分隔線效果*/ .nav li::before, .nav li::after{ content:""; position:absolute; top:14px; height: 25px; width: 1px; } .nav li::after{ right: 0; /* 線性漸變 */ background: -moz-linear-gradient(top, rgba(255,255,255,0), rgba(255,255,255,.2) 50%, rgba(255,255,255,0)); background: -webkit-linear-gradient(top, rgba(255,255,255,0), rgba(255,255,255,.2) 50%, rgba(255,255,255,0)); background: -o-linear-gradient(top, rgba(255,255,255,0), rgba(255,255,255,.2) 50%, rgba(255,255,255,0)); background: -ms-linear-gradient(top, rgba(255,255,255,0), rgba(255,255,255,.2) 50%, rgba(255,255,255,0)); background: linear-gradient(top, rgba(255,255,255,0), rgba(255,255,255,.2) 50%, rgba(255,255,255,0)); } .nav li::before{ left: 0; background: -moz-linear-gradient(top, #ff625a, #9e3e3a 50%, #ff625a); background: -webkit-linear-gradient(top, #ff625a, #9e3e3a 50%, #ff625a); background: -o-linear-gradient(top, #ff625a, #9e3e3a 50%, #ff625a); background: -ms-linear-gradient(top, #ff625a, #9e3e3a 50%, #ff625a); background: linear-gradient(top, #ff625a, #9e3e3a 50%, #ff625a); } /*刪除導(dǎo)航第一個(gè)導(dǎo)航項(xiàng)左邊的分隔線*/ .nav li:first-child::before{ background: none; } /*刪除導(dǎo)航最后一個(gè)導(dǎo)航右邊的分隔線*/ .nav li:last-child::after{ background: none; } .nav a, .nav a:hover{ color:#fff; text-decoration: none; } </style> </head> <body> <ul class="nav"> <li><a href="">首頁(yè)</a></li> <li><a href="">個(gè)人簡(jiǎn)介</a></li> <li><a href="">作品集</a></li> <li><a href="">博客</a></li> <li><a href="">資源</a></li> <li><a href="">聯(lián)系我</a></li> </ul> </body></html>效果圖:


總結(jié):
1、body部分用無(wú)序列表
2、(1)hover
鼠標(biāo)移上時(shí)的效果。
(2)疑問(wèn)::before和:before的區(qū)別
簡(jiǎn)單來(lái)說(shuō)單冒號(hào)(:)用于CSS3偽類,雙冒號(hào)(::)用于CSS3偽元素。
w3c關(guān)于css選擇器的規(guī)范:
A pseudo-element is made of two colons (::) followed by the name of the pseudo-element.
This :: notation is introduced by the current document in order to establish a discrimination between pseudo-classes and pseudo-elements. For compatibility with existing style sheets, user agents must also accept the previous one-colon notation for pseudo-elements introduced in CSS levels 1 and 2 (namely, :first-line, :first-letter, :before and :after). This compatibility is not allowed for the new pseudo-elements introduced in CSS level 3.
簡(jiǎn)單翻譯:偽元素由雙冒號(hào)和偽元素名稱組成。雙冒號(hào)是在當(dāng)前規(guī)范中引入的,用于區(qū)分偽類和偽元素。不過(guò)瀏覽器需要同時(shí)支持舊的已經(jīng)存 在的偽元素寫法,比如:first-line、:first-letter、:before、:after等,而新的在CSS3中引入的偽元素則不允許再支持舊的單冒號(hào)的寫法。
那么現(xiàn)在就可以完整的回答標(biāo)題中的問(wèn)題了,對(duì)于CSS2之前已有的偽元素,比如:before,單冒號(hào)和雙冒號(hào)的寫法::before作用是一樣的。
所以,如果你的網(wǎng)站只需要兼容webkit、firefox、opera等瀏覽器,建議對(duì)于偽元素采用雙冒號(hào)的寫法,如果不得不兼容IE瀏覽器,還是用CSS2的單冒號(hào)寫法比較安全。
總結(jié)
以上所述是小編給大家介紹的使用CSS制作立體導(dǎo)航欄,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選