> 웹 프론트엔드 > HTML 튜토리얼 > CSS练习-导航栏斜线分隔-利用伪元素 - 五木十架

CSS练习-导航栏斜线分隔-利用伪元素 - 五木十架

WBOY
풀어 주다: 2016-05-22 17:19:45
원래의
1882명이 탐색했습니다.

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

先写html结构。

<span style="color: #008000;"><!--</span><span style="color: #008000;"> 导航栏begin </span><span style="color: #008000;">--></span>
    <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="header_right fr"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">="#"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="link"</span><span style="color: #0000ff;">></span>Home<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">="#"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="link"</span><span style="color: #0000ff;">></span>About<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">="#"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="link"</span><span style="color: #0000ff;">></span>Features<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">="#"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="link"</span><span style="color: #0000ff;">></span>Blog<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">="#"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="link"</span><span style="color: #0000ff;">></span>Shop<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="alarm fr"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><span style="color: #800000;">img </span><span style="color: #ff0000;">src</span><span style="color: #0000ff;">="./images/alarm.png"</span><span style="color: #ff0000;"> alt</span><span style="color: #0000ff;">="alarm"</span> <span style="color: #0000ff;">/></span><span style="color: #800000;">images</span><span style="color: #0000ff;">><span style="color: #800000;">i </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="alarm_number"</span><span style="color: #0000ff;">></span>2<span style="color: #0000ff;"></span><span style="color: #800000;">i</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>
 <span style="color: #008000;"><!--</span><span style="color: #008000;"> 导航栏end </span><span style="color: #008000;">--></span></span></span></span></span></span></span></span></span></span>
로그인 후 복사

再是样式

<span style="color: #800000;">.link:before</span>{<span style="color: #ff0000;">content</span>:<span style="color: #0000ff;"> "/"</span>;<span style="color: #ff0000;">margin</span>:<span style="color: #0000ff;">0 24px</span>;<span style="color: #ff0000;">color</span>:<span style="color: #0000ff;"> grey</span>;}<span style="color: #800000;">
.link:first-child:before</span>{<span style="color: #ff0000;">display</span>:<span style="color: #0000ff;">none</span>;}
로그인 후 복사

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

效果是这样的

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

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿