封面圖片來自Google
css
經過元素類型 tagName
、*
、.class
或 #id
匹配一個或多個元素。html
經過 屬性 / 屬性值 匹配一個或多個元素。css3
Presenceweb
類型 | 匹配結果 |
---|---|
[ attr ] |
匹配包含 attr 屬性的全部元素 |
[ attr = val ] |
匹配 attr 屬性值爲 val 的全部元素 |
[ attr ~= val ] |
匹配 attr 屬性中包含 val 詞彙( space-separated )的全部元素 |
Substringchrome
類型 | 匹配結果 |
---|---|
[ attr ^= val ] |
匹配 attr 屬性中以 val 開頭的全部元素 |
[ attr |= val ] |
匹配 attr 屬性中以 val 或者 val- 開頭的全部元素 |
[ attr $= val ] |
匹配 attr 屬性中以 val 結尾的全部元素 |
[ attr *= val ] |
匹配 attr 屬性中包含 val 的全部元素 |
僞類:匹配元素的相關狀態和屬性,如 :hover
:first-child
:nth-child()
,單冒號。
僞元素:匹配元素的相關位置, 如 ::after
::first-letter
::selection
,雙冒號。express
組合選擇器:組合使用多個選擇器。瀏覽器
類型 | 組合 | 匹配結果 |
---|---|---|
選擇器組 | A , B | 匹配 A or B選擇器規則 |
後代選擇器 | A B | 匹配B選擇器規則,且B是A的後代(子孫) |
子代選擇器 | A > B | 匹配B選擇器規則,且B是A的子代(必須是直接子代) |
相鄰兄弟選擇器 | A + B | 匹配B選擇器規則,且B是A的弟弟(AB屬於同一父代,且B緊跟A的後面) |
任一兄弟選擇器 | A - B | 匹配B選擇器規則,且B是A的任意弟弟(AB屬於同一父代,且B在A以後,不必定緊挨) |
優先級按如下規則遞增:bash
*
、組合選擇器( , > + -
'
')和否認僞類:not()
對優先級沒有影響(在 :not()
內部聲明的選擇器仍是會按照規則影響)tagName
、僞元素選擇器 ::
.class
、 屬性選擇器 [ attr ]
、僞類選擇器 :
#id
< tagName style="" >
!important
- 數值
- 百分比
- 顏色:背景顏色 background-color 文字顏色 color 邊框顏色 border
- colorName
- HEX
- RGB
- HSL
- RGBA HSLA
- Opacity
- 函數
- rgb() rgba() hsla() linear-gradient()
- rotate() translate()
- calc()
- url()
複製代碼
- px
- em em are the most common **relative** unit you'll use in web development.
- rem
- ex ch
- vw vh
- 無單位值
- 動畫 s deg
複製代碼
margin
:外邊距,顏色透明border
:邊框padding
:內邊距,顏色透明content
:盒子內容
width
和height
: Content
的寬度和高度,默認爲 auto
,即瀏覽器自動計算。max-width/min-width
min-height/max-height
注意!再提一下,設置元素的
width
和height
,其實是設置的content
區域的width
和height
。元素的實際尺寸還需計算padding
、border
和margin
。 有幾種計算模型須要瞭解:markdown
Total element width = width + left padding + right padding + left border + right border + left margin + right margin
Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin
複製代碼
OUTSIDE the
borders
, to make the element "stand out".ide
輪廓指的是邊框外的區域,目的是爲了設置使元素顯得突出的樣式
溢出 overflow
控制的是內容區域 content
太大而溢出一片區域時候的狀況。
值 | 匹配結果 |
---|---|
visible |
默認值,溢出部分不會被裁減,內容區域 content 會渲染到元素盒子以外 |
hidden |
溢出部分會被裁減, 不可見 |
scroll |
溢出部分會被裁減,但會出現滾動條以查看內容(始終存在垂直和水平滾動條) |
auto |
和scroll 類似,但只會在必要時,出現滾動條(只有溢出的方向出現滾動條) |
background-clip: border-box|padding-box|content-box|initial|inherit;
複製代碼
BFC
BFC ( block-formatting contexts )
Chrome開發者工具使用指南 | Google Developer
@media
@media not|only mediatype and (expressions) {
CSS-Code;
}
複製代碼
<link rel="stylesheet" media="mediatype and|not|only (expressions)" href="print.css"> 複製代碼
參考: