学习笔记:伪类的应用(after/before/nth-child)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>CSS伪类</title>
        <style type="text/css">
           *{
               margin:0;
               padding:0;
               font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
               font-size: 14px;
           }
           .box{
               margin:20px auto;
               width:300px;
               padding:30px;
               border:1px dashed green; 
           }
           .box p{
               line-height: 30px;
           } 
           .box p:before{  /*before after:在一个元素标签前/后创建一个
           新的虚拟标签,可以给虚拟标签加样式和内容*/
               display:block;
               height:30px;
               line-height: 30px;
               text-align: center;
               content:"珠峰";
               background: lightblue;
           }
           .box p:after{
               display:block;
               height:30px;
               line-height: 30px;
               text-align: center;
               content:"珠峰";
               background: lightgreen;
           }
           .clear{
               zoom:1;
           }
           .clear:after{
               display:block;
               width:0;
               height:0;
               content:"";
               overflow:hidden;
               clear:both;
           }
           ul,li{
               list-style:none;
           }
           .list{
               width:300px;
               margin:20px auto;
               border:1px solid #000;
               padding:30px;
           }
           .list li{
               width:100px;
               float:left;
               height:100px;
               background: lightyellow;
           }
           .list li:nth-child(4n+1){ /*让各块颜色不一样,括号里面自行设置*/
               background:red;
           }
           .list li:nth-child(4n+2){
               background: orange;
           }
           .list li:nth-child(4n+3){
               background: yellow;
           }
           .list li:nth-child(4n+4){
               background: green;
           }
        </style>
    </head>
    <body>
        <div class="box">
         <p>
                     在互联网技术高速发展的今天,我们已经进入到了一个充满信息化技术的时代,
                     信息技术的发展俨然已经成为我国社会发展的重要战略资源,因此各个国家以及企业
                     对于信息的竞争也演变的越来越激烈。信息安全一直以来都是国家安全与社会安全的
                     基石,它全方位的影响着我国的经济、政治、文化、社会、军事生活的各个方面,是影
                     响我国发展与长远利益的一个重大问题。
         </p>
        </div>
        <ul class="list clear">  <!--清除浮动,加上clear-->
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <script type="text/javascript"></script>
    </body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值