-------------id选择器(1对1的关系,一个元素只能对应一个ID,同样的一个ID也只能对应一个元素)---------------
html:
<div id="only"></div>
css:
#only{
width:100px;
height:100px;
background-color:red;
}
-------------class选择器(多对多的关系,一个元素可以有多个class,同样一个class能够让多个元素使用)---------------
html:
<div class="class1 class2 .... classN"></div>
css:
.class1{
width:100px;
height:100px;
background-color:red;
}
-------------标签选择器---------------
html:
<div></div>
css:
div{
width:100px;
height:100px;
background-color:red;
}
-------------通配符选择器---------------
css:
*{
background-color:red;
}
-------------属性选择器---------------
html:
<input type="text">
<input type="password">
css:
input [type="text"]{
background-color:red;
}
-------------------------优先级(权重)----------------------
优先级:
!important > 行间样式 > id选择器 > (属性选择器 == class选择器) > 标签选择器 > 通配符选择器
权重:
!important(正无穷)
行间样式(1000)
id选择器(100)
属性选择器||class选择器||伪类(10)
标签选择器||伪元数(1)
通配符选择器(0)
(ps:他们之间的进制是256)