课堂小结。

目录

一、结构选择器、

        1.1  选择第一个元素

        1.2选择最后一个元素

         1.3选择第几个元素

          1.4除了...之外

 二、伪类选择器

          2.1元素1:hover 元素2:

         2.2 :link:

          2.3 :active :

          2.4 :visited:

三、伪元素选择器

         3.1元素1::before

         3.2元素1::after


一、结构选择器、

        1.1  选择第一个元素

            ① 父元素>元素1:first-child 选择第一个元素1,要求元素1是父元素里面的第一个子元素

            ②父元素>元素1:first-of-type 选择第一个元素1,父元素先按元素种类(标签名)先分组,                 然后在元素1组中选择第一个元素

        1.2选择最后一个元素

            ①父元素>元素1:last-child 选择最后一个元素1,要求元素1是父元素里面的最后一个子元素

            ②父元素>元素1:last-of-type 选择最后一个元素1,父元素先按元素种类(标签名)先分组,然后在元素1组中选择最后一个元素

         1.3选择第几个元素

            ①父元素>元素1:nth-child(num) 选择第num个元素1,要求元素1是父元素中的第num个子元素

           ②父元素>元素1:nth-of-type(num) 选择第num个元素1,父元素先按元素种类(标签名)先分组,然后在元素1组中选择第num个元素

            备注: 2n+1/odd 选择所有奇数子元素

                  2n/even 选择所有偶数个的子元素

          1.4除了...之外

             :not(条件) {}

<style>
        *:not(del) {
            list-style: none;
            text-decoration: none;
        }

        ul>li:not(:last-of-type) {
            background-color: aqua;
        }

        ul li:first-of-type {
            font-size: 20px;
            color: red;
        }

        ul h3:first-of-type {
            color: pink;
        }

        ol li:first-of-type {
            color: yellow;
        }

        ol li:last-of-type {
            color: rgb(207, 101, 40);
        }

      
        ol>li:nth-of-type(5) {
            color: goldenrod;
        }

        ol>li:nth-of-type(2n+1) {
            background-color: aqua;
        }

        ol>li:nth-of-type(2n) {
            background-color: gold;
        }

        ol>p:nth-of-type(even) {
            background-color: aqua;
        }

        ol>p:nth-of-type(odd) {
            background-color: gold;
        }
    </style>
</head>

<body>
    <ul>
        <p>你是我的爱</p>
        <h3>Lorem, ipsum dolor.</h3>
        <h3>前道</h3>
        <h3>结构选择器</h3>
        <li>lorem1</li>
        <li>lorem2</li>
        <li>lorem3</li>
        <li>lorem4</li>
        <li>lorem5</li>
        <li>lorem6</li>
        <a href="#">我是a</a>
    </ul>
    <hr>
    <ol>
        <p>我是P1</p>
        <p>我是P2</p>
        <p>我是P3</p>
        <li>我是li1</li>
        <li>我是li2</li>
        <li>我是li3</li>
        <li>我是li4</li>
        <li>我是li5</li>
        <li>我是li6</li>
    </ol>
    <del>1000元</del>
    </ul>
</body>

 二、伪类选择器

          2.1元素1:hover 元素2:

                          设置鼠标悬停在元素1时元素2的样式,

                          如果hover后面没有元素,则表示设置样式对象是元素1

         2.2 :link:

                         超链接还没有被访问

          2.3 :active :

                         超链接正在被访问

          2.4 :visited:

                          超链接已经被访问了

                          当设置超链接(a)四种状态时,顺序:link->:visited->:hover->:active

  <style>
        * {
            list-style: none;
            width: 180px;
        }

        ul>li:hover {
            background-color: orange;
        }

        a {
            text-decoration: none;
        }

        ol>li:hover>a {
            text-decoration: underline;
        }

        .one:link {
            color: chartreuse;
        }

        .one:visited {
            color: fuchsia;
        }

        .one:hover {
            color: green;
        }

        .one:active {
            color: red;
        }
    </style>
</head>

<body>

    <a href="#" class="one">我是你爸爸</a>
    <ul>
        <li>jw1</li>
        <li>jw2</li>
        <li>jw3</li>
        <li>jw4</li>
    </ul>
    <ol>
        <li><a href="#">Lorem1</a>我的</li>
        <li><a href="#">Lorem2</a>我的</li>
        <li><a href="#">Lorem3</a>我的</li>
        <li><a href="#">Lorem4</a>我的</li>
    </ol>
</body>

三、伪元素选择器

         3.1元素1::before

                          给元素1添加第一个子元素(默认是行元素)

         3.2元素1::after

                          给元素1添加最后一个子元素(默认是行元素)

                          注意点:::before和::after必须与content属性一起连用

<style>
    
        div::before{
            content: "";
            width: 1px;
            height: 50px;
            background-color: red;
            display: inline-block;
        }
        div::after{
            content: "";
            width: 1px;
            height: 50px;
            background-color: black;
            display: inline-block;
        }
    </style>
</head>
<body>
    <div>
      
        <span>
            我的
        </span>
    </div>
</body>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值