zoukankan      html  css  js  c++  java
  • CSS 选择器 :last-child与:last-of-type的区别

    :last-child----represents the last element among a group of sibling elements.

    CSS伪类 :last-child 代表在一群兄弟元素中的最后一个元素。

    • :last-child与:last-of-type的区别
    • 从代码和图可以看出:last-child选择了最后一个li标签。

      同时,我们换另外一段代码,看看是否还有这样的效果。

      :last-child与:last-of-type的区别
    •  从代码和图可以看出,:last-child并没有起到我们想要的作用。如果,这个时候去掉最后的div标签,再看看效果。

      •  
        :last-child与:last-of-type的区别
      • 这时,效果出来了,那么,可以总结了。

        :last-child表示其父元素的最后一个子元素,且这个元素是css指定的元素,才可以生效。

        注意::last-child 这里父元素的子元素一定是css指定元素才生效

        :last-of-type

         
        • 关于:last-of-type手册中是这么解释的:

          The :last-of-type CSS pseudo-class represents the last element of its type among a group of sibling elements.

          CSS伪类:last-of-type代表在一群兄弟元素中的最后一个指定类型的元素。

          直接用上面两个栗子。

          没有干扰元素,OK。

          :last-child与:last-of-type的区别
        • 有干扰元素,OK。

          :last-child与:last-of-type的区别
        • :last-of-type表示其父元素下的最后一个指定类型的元素,不必要求父元素最后一个子元素与css指定元素一样!!!!

           

        结尾

         
        • 总结了一番,对于什么场景下使用:last-child和:last-of-type又了相应的认识,以后犯错的可能性就会降低了很多。

          :last-child表示其父元素的最后一个子元素,且这个元素是css指定的元素,才可以生效。 注意::last-child 这里父元素的子元素一定是css指定元素才生效

          :last-of-type表示其父元素下的最后一个指定类型的元素,不必要求父元素最后一个子元素与css指定元素一样!!!!

  • 相关阅读:
    [Typescript] What is a Function Type ? Function Types and Interfaces
    [NPM] Add comments to your npm scripts
    警告: 隐式声明与内建函数‘exit’不兼容 [默认启用]
    小数循环节
    [置顶] API相关工作过往的总结之整体介绍
    [置顶] 如何运行用记事本写的java程序
    Linux进程间通信——使用共享内存
    Linux内核数据包的发送传输
    ESB 企业服务总线
    URAL 1244
  • 原文地址:https://www.cnblogs.com/mmzuo-798/p/11891836.html
Copyright © 2011-2022 走看看