權重大小
內嵌權重為1000
<p style="color: yellow;">ALEX</p>
id選擇器的權重為100,類選擇器的權重為10,標簽選擇器的權重為1.
/*1 1 1*/
#box1 .wrap2 p{color: red;
}
當權重一樣的時候,是以后設置的屬性為準,后來者居上。
如果標簽元素被選中,誰的權重大,就顯示誰的屬性
.如果沒有被選中標簽元素,權重為0。
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title></title><style type="text/css">/*此時標簽沒有被選中,權重為0*/.father{background: green;color: red;}p{color: yellow;}</style></head><body><div class="father" ><div class="child"><p>ALEX</p></div></div></body>
</html>
如果權重都是0 。
權重都是0:"就近原則" : 誰描述的近,就顯示誰的屬性
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title></title><style type="text/css">/*顯示*/.child {color: gray;}.father{background: green;color: red;}</style></head><body><div class="father" ><div class="child"><p>ALEX</p></div></div></body>
</html>
!impantant 權重無限大
.child p{color: gray !important;}