Home  >  Article  >  Web Front-end  >  CSS练习-导航栏斜线分隔-利用伪元素_html/css_WEB-ITnose

CSS练习-导航栏斜线分隔-利用伪元素_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:24:301264browse

开始切第一张图了,第一个遇到的问题是顶部导航栏这里,用斜线分割。想到的思路是用伪类:before或者:after实现

先写html结构。

<!-- 导航栏begin -->    <div class="header_right fr">    <a href="#" class="link">Home</a>    <a href="#" class="link">About</a>    <a href="#" class="link">Features</a>    <a href="#" class="link">Blog</a>    <a href="#" class="link">Shop</a>    <div class="alarm fr">    <img src="./images/alarm.png" alt="alarm" /></images><i class="alarm_number">2</i>    </div>    </div> <!-- 导航栏end -->

再是样式

.link:before{content: "/";margin:0 24px;color: grey;}.link:first-child:before{display:none;}

先用:bofore,设定内容是"/",前后margin,颜色。再用first-child将第一个元素之前的伪类去掉。

效果是这样的

似乎没有设计图里的斜线倾斜角度大呢……

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn