AI智能
改变未来

css更多的选择器(伪类/伪元素选择器补充)

更多的伪类/伪元素选择器

  • 伪类选择器
  • first-child/last-child
  • first-of-type/last-of-child
  • nth-child
  • nth-of-type
  • 伪元素选择器
    • first-letter
    • first-line
    • selection

    伪类选择器

    first-child/last-child

    选择第一个子元素

    first-of-type/last-of-child

    选中子元素中,指定的第一个子元素

    nth-child

    选中指定位置的子元素 ** (a:nth-child(7)选中第七个a子元素)**
    也可以用变量**(a:nth-child(2n) 选中为偶数的a的子元素)**

    关键字:even == 2n;odd == 2n +1;

    nth-of-type

    选中子指定子元素中,指定的第几个某类型元素
    a:nth-of-type(enen) (选中a元素中为偶数的a子元素,不管中之间是否有其他元素

    伪元素选择器

    first-letter

    选择元素中的第一个字母

    first-line

    选中元素中的第一行文字

    selection

    选中被用户框选的文字

    赞(0) 打赏
    未经允许不得转载:爱站程序员基地 » css更多的选择器(伪类/伪元素选择器补充)