CSS选择器

我们可以将 CSS 选择器分为五类:

  • 简单选择器
  • 组合器选择器
  • 伪类选择器
  • 伪元素选择器
  • 属性选择器

     id 选择器(简单)

    id 选择器使用 HTML 元素的 id 属性来选择特定元素。

     id="div1" 的 HTML 元素:

    #div1 {
      text-align: center;
      color: red;
    }

     

    类选择器

    有特定 class 的元素,写一个(.)字符,后面跟类名。

     class="center" 

    .center {
      text-align: center;
      color: red;
    }

    通配符选择器

    通配符选择器(*)

     

    * {
      text-align: center;
      color: blue;
    }

    分组选择器

    h1、h2 和 p 元素具有相同的样式定义

    h1 {
      text-align: center;
      color: red;
    }
    
    h2 {
      text-align: center;
      color: red;
    }
    
    p {
      text-align: center;
      color: red;
    }

     



posted @ 2021-11-12 17:17  李半仙儿、、、、  阅读(43)  评论(0)    收藏  举报