Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Practices

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

CSS Practices

Avatar for Ryan Chung

Ryan Chung

May 22, 2020
Tweet

More Decks by Ryan Chung

Other Decks in Technology

Transcript

  1. Box Model 箱子模型 ⚫ Margin –邊界 ⚫ Border – 邊框

    ⚫ Padding – 框距 ⚫ Content - 內容、文字/影像
  2. ⚫ margin-xxxx 分開標示 ⚫ margin-bottom ⚫ margin-left ⚫ margin-right ⚫

    margin-top 邊界 Margin ⚫ margin 一次標示 ⚫ 10px − 上:10px、右:10px、下:10px、左:10px ⚫ 10px 5px − 上:10px、右:5px、下:10px、左:5px ⚫ 10px 5px 15px − 上:10px、右:5px、下:15px、左:5px ⚫ 10px 5px 15px 20px − 上:10px、右:5px、下:15px、左:20px
  3. 邊框 Border 1/2 ⚫ border-style 設定邊框樣式 (可每一邊不同) ⚫ 樣式 −

    none, dotted, dashed, solid, double, groove 溝槽 − ridge 隆起, inset, outset, hidden ⚫ 四邊分開設 − border-top-style − border-right-style − border-bottom-style − border-left-style ⚫ 一次一起設 − border-style:dotted solid double dashed 上,右,下,左 − border-style:dotted solid double 上,左右,下 − border-style:dotted solid 上下,左右 − border-style:dotted 四邊相同
  4. 邊框 Border 2/2 ⚫ border-width 設定邊框寬度(框的粗細) ⚫ 四邊分開設 − border-top-width

    − border-right-width − border-bottom-width − border-left-width ⚫ 一次一起設 − border-width:10px 5px 15px 20px 上,右,下,左 − border-width:10px 15px 5px 上,左右,下 − border-width:10px 5px 上下,左右 − border-width:10px 四邊相同 ⚫ border-color 顏色 ⚫ border 一次設定四邊的樣式、寬度與顏色 ⚫ border:5px solid red
  5. CSS3 動畫  @-webkit-keyframes name 定義動畫影格  name名稱 與 animation-name

    對應  time可設定from、to或x% 決定每個時間點要呈現什麼效果  -webkit-animation 定義動畫屬性  animation-name:名稱,與keyframes對應  animation-duration:動畫播放時間長度(秒)  animation-iteration-count:播放次數( n or infinite)  animation-timing-function:ease、linear、ease-in、ease-out、ease-in-out  animation-play-state:running、paused  animation-delay:隔多久再開始
  6. CSS規則套用的優先權 Specificity • 直接寫在HTML組件的style屬性 • 優先權值:1000 • CSS選擇器使用ID的方式 • 優先權值:100

    • CSS選擇器使用class, pseudo-class或限定屬性 • 優先權值:10 • CSS選擇器使用HTML組件、偽組件(pseudo-element) • 優先權值:1
  7. 計算 Specificity • #container ul#menu li.active ul li:hover {} •

    #container:100 • ul:1 • #menu:100 • li:1 • .active:10 • ul:1 • li:1 • :hover:10 Specificity:224 https://www.codecaptain.io/tools/css-specificity-calculator