單個標籤 直接使用標籤名
多個標籤 複雜選擇器
div p 選擇div內部的全部p元素
div > p 父元素爲div的全部p元素
li + li 緊接在li以後的li元素
p ~ ul 選擇前面有p元素的每一個ul元素css
好比對多個li添加下劃線
可直接使用html
ul li+li{ border-top:1px solid #ccc; }
id/class選擇器 略過佈局
input[type='text']{ }
a:link a:hover a:activted a:visited
a標籤的四個僞類排列順序和緣由spa
link指有連接屬性時 visited 連接地址已經被訪問過 active 被用戶激活 hover鼠標懸停code
根據使用情景肯定a狀態htm
緣由:link和visited爲靜態常態,但一旦被訪問應該覆蓋原樣式
在鼠標操做時,a標籤同時具有hover 和active 狀態 因此active必須放在hover以後element
table tr:nth-child(even){} table tr:nth-child(odd){} table tr:first-child{} table tr:last-child{} table tr:nth-child(2n+1)
:before 和 :after很是經常使用
例如:input
<style> span:before{ content:'你好,' } span:after{ content:'!' } </style> <span>Shirly</span>
使用注意:it
儘可能對外層添加class, 內層使用多級選擇器,下降初步佈局樣式的優先級以便js處理table
首先明確選擇器表達式的重要程度。
公式: I-C-E
I–id —–C-class —— E-element
遇到一個id就往特指度數值中加100,遇到一個class就往特指度數值中加10,遇到一個element就往特指度數值中加1
還有一個重點要注意:!important優先級最高,高於上面一切。* 選擇器最低,低於一切。
box-sizing:border-box;
縱向的margin會重疊,值較大的覆蓋掉較小的。
div{ border:10 solid; border-color:#444 transparent transparent transparent ; width:0; }