HTML5基础加强css样式篇(常用伪元素选择器after,before)(十五)

注:1伪元素与元素的区别:无法获取文本内容;

         2.规范要求使用::实际使用:(支持IE8);

         3.伪元素和本身元素在同一层级

1.after伪元素:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        /*.box::after {*/
        .box:after {
            content: "Hi ";

            font-size: 36px;

            display: block;
        }
        .box{
            border: 1px solid red;
        }

        /*1.伪元素before与元素区别 : 无法获取文本内容*/
        /*2.规范要求使用:: 实际使用: 支持IE8*/
    </style>
</head>
<body>

    <div class="box">
        <span>Hello</span>
    </div>

<script type="text/javascript">



</script>
</body>
</html>


2.before伪元素:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box::before {
            content: "Hi ";

            font-size: 36px;

            display: block;
        }


        .box{
            border: 1px solid red;
        }
    </style>
</head>
<body>

    <div class="box">
        <span>Hello</span>
    </div>

<script type="text/javascript">



</script>
</body>
</html>

3.before和after的具体使用(解决高度塌陷)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .wrapper{
            background-color: yellow;
        }

        .wrapper:after{
            content: "";
            /*注意:通过伪元素清除浮动,必须设置 display: block*/
            display: block;
            clear: both;
        }

        .box{
            width: 200px;
            height: 200px;
            background-color: blue;
            float: left;
        }


        /*.clear-fix{*/
            /*clear: both;*/
        /*}*/


    </style>
</head>
<body>

    <div class="wrapper">
        <div class="box"></div>
        <!--<div class="clear-fix"></div>-->
    </div>


<script type="text/javascript">


</script>
</body>
</html>

4.属性元素选择器和伪元素的综合使用:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">

        ul{
            list-style: none;
            margin: 0;
            padding: 0;
        }

        [href$=".doc"]:before{
            content: "";
            display: inline-block;
            width: 24px;
            height: 24px;
            background: url("img/icon_doc.png") no-repeat;

            vertical-align: middle;

        }

        [href$=".xls"]:before{
            content: "";
            display: inline-block;
            width: 24px;
            height: 24px;
            background: url("img/icon_xls.png") no-repeat;

            vertical-align: middle;

        }

        [href$=".pdf"]:before{
            content: "";
            display: inline-block;
            width: 24px;
            height: 24px;
            background: url("img/icon_pdf.png") no-repeat;

            vertical-align: middle;

        }

        [href$=".mp3"]:before{
            content: "";
            display: inline-block;
            width: 24px;
            height: 24px;
            background: url("img/icon_mpg.png") no-repeat;

            vertical-align: middle;

        }
        [href$=".html"]:before{
            content: "";
            display: inline-block;
            width: 24px;
            height: 24px;
            background: url("img/icon_xml.png") no-repeat;

            vertical-align: middle;

        }


        span{
            vertical-align: middle;
            margin-left: .5em;
        }

        ul li{
            line-height: 2;
        }

    </style>
</head>
<body>

<ul>
    <li><a href="file/test.doc"><span>世界真其美妙.doc</span></a></li>
    <li><a href="file/test.xls"><span>销售报表.xls</span></a></li>
    <li><a href="file/test.pdf"><span>JS权威指南.pdf</span></a></li>
    <li><a href="file/test.mp3"><span>南山南.mp3</span></a></li>
    <li><a href="file/test.html"><span>test.html</span></a></li>
</ul>


<script type="text/javascript">


</script>
</body>
</html>

效果如下:






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咸鸭蛋炒饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值