課程
/前端開(kāi)發(fā)
/HTML/CSS
/十天精通CSS3
如何使用漸變與偽元素制作導(dǎo)航分割線
2017-01-25
源自:十天精通CSS3 5-5
正在回答
分別使用before和after在導(dǎo)航節(jié)點(diǎn)前后都加上偽元素,設(shè)置上不同顏色,這樣前一個(gè)節(jié)點(diǎn)的after和后一個(gè)節(jié)點(diǎn)before貼在一起組成的分割線會(huì)好看。
分割線兩邊透明,中間不透明,漸變;
去掉最前面節(jié)點(diǎn)的before和最后面節(jié)點(diǎn)的after,導(dǎo)航完成。
<!doctype?html> <html> <head> ????<meta?charset="UTF-8"> <title>CSS制作立體導(dǎo)航</title> <link?rel="stylesheet"?> <style> body{ ?background:?#ebebeb; } .nav{ ?width:560px; ?height:?50px; ?font:bold?0/50px?Arial; ?text-align:center; ?margin:40px?auto?0;? ?????background:?#f65f57; ?/*制作圓*/ ?border-radius:5px; ??????????/*制作導(dǎo)航立體風(fēng)格*/ ??????????box-shadow:0?5px?#b64b41; } .nav?a{ ?display:?inline-block; ?-webkit-transition:?all?0.2s?ease-in; ?-moz-transition:?all?0.2s?ease-in; ?-o-transition:?all?0.2s?ease-in; ?-ms-transition:?all?0.2s?ease-in; ?transition:?all?0.2s?ease-in; } .nav?a:hover{ ?-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:?13px; ?text-shadow:1px?2px?4px?rgba(0,0,0,.5); ?list-style:?none?outside?none; } /*使用偽元素制作導(dǎo)航列表項(xiàng)分隔線*/ .nav?li::before, .nav?li::after{ ???content:""; ???position:absolute; ???top:14px; ???width:1px; ???height:25px; } .nav?li::before{ ???left:0; ???background:-moz-linear-gradient(to?top,#f65f57,#9e3e3a?50%,#f65f57); ???background:-webkit-linear-gradient(to?top,#f65f57,#9e3e3a?50%,#f65f57); ???background:-o-linear-gradient(to?top,#f65f57,#9e3e3a?50%,#f65f57); ???background:-ms-linear-gradient(to?top,#f65f57,#9e3e3a?50%,#f65f57); ???background:linear-gradient(to?top,#f65f57,#9e3e3a?50%,#f65f57); } ???.nav?li::after{ ???????right:0; ???????background:-moz-linear-gradient(to?top,rgba(255,255,255,0),?rgba(255,255,255,.2)?50%,?rgba(255,255,255,0)); ???????background:-webkit-linear-gradient(to?top,rgba(255,255,255,0),?rgba(255,255,255,.2)?50%,?rgba(255,255,255,0)); ???????background:-o-linear-gradient(to?top,rgba(255,255,255,0),?rgba(255,255,255,.2)?50%,?rgba(255,255,255,0)); ???????background:-ms-linear-gradient(to?top,rgba(255,255,255,0),?rgba(255,255,255,.2)?50%,?rgba(255,255,255,0)); ???????background:linear-gradient(to?top,rgba(255,255,255,0),?rgba(255,255,255,.2)?50%,?rgba(255,255,255,0)); ???} ????????/*刪除第一項(xiàng)和最后一項(xiàng)導(dǎo)航分隔線*/ .nav?li:first-child::before, .nav?li:last-child::after?{ ???background:none; } .nav?a, .nav?a:hover{ ?color:#fff; ?text-decoration:?none; } </style> </head> <body> <ul> ?????<li><a?href="">Home</a></li> ?????<li><a?href="">About?Me</a></li> ?????<li><a?href="">Portfolio</a></li> ?????<li><a?href="">Blog</a></li> ?????<li><a?href="">Resources</a></li> ?????<li><a?href="">Contact?Me</a></li> </ul> </body> </html>
舉報(bào)
本課程為CSS3入門教程,深刻詳解CSS3知識(shí)讓網(wǎng)頁(yè)穿上絢麗裝備
2 回答徑向漸變?
7 回答偽類與偽元素的區(qū)別?
2 回答這個(gè)偽元素哪里來(lái)的?為什么要用漸變?難道不是用border做個(gè)邊框線么?
1 回答徑向漸變效果
1 回答經(jīng)向漸變的語(yǔ)法
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-01-26
分別使用before和after在導(dǎo)航節(jié)點(diǎn)前后都加上偽元素,設(shè)置上不同顏色,這樣前一個(gè)節(jié)點(diǎn)的after和后一個(gè)節(jié)點(diǎn)before貼在一起組成的分割線會(huì)好看。
分割線兩邊透明,中間不透明,漸變;
去掉最前面節(jié)點(diǎn)的before和最后面節(jié)點(diǎn)的after,導(dǎo)航完成。