class选择器:

<p class="p1">

.p1{
  color:red;
  .....    
}

 

id选择器:

<p id="p2">

#p1{
  color:red;
  .....    
}

 

异同:

相同点:可以应用于任何元素
不同点:

  1.id全局唯一;class无要求;

  2.class选择器可以写成下面形式:

<p class="p p1">

.p{
  color:red;
  .....    
}


.p1{
 font-size:20px;
  .....    
}

  id只能有一个。错误示例:

<p id="p p2">   <!-- 这是错误写法 -->

 

相关文章:

  • 2021-12-22
  • 2021-06-17
  • 2021-06-02
  • 2022-01-20
  • 2022-02-16
  • 2021-05-19
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
相关资源
相似解决方案