SlideShare a Scribd company logo
CSS
Box model, Position, Display
CSS.pptx
Padding
• 沒有padding,內容會黏著邊框。
• 會撐起Border
• 會吃到背景色。
CSS.pptx
CSS.pptx
Margin
• 讓element和其他element之間有一定的距離
• 不會吃到背景色。
• Margin Collapsing
CSS.pptx
CSS.pptx
Another Example
Paragraph和Heading的距離是多少?
CSS.pptx
Long Time Ago
There was a Front-End Engineer…
CSS.pptx
結果變成這個樣子:
CSS.pptx
這個時候出現問題了!
變得超可怕!
CSS.pptx
現在2018,只需要Box-sizing
Box-sizing: border-box
content-box vs. border-box
Position
static, relative, fixed, absolute etc.
Static
• Position的預設值
• 照Browser默認的方式排
• 無法被top, bottom, left, right所影響
CSS.pptx
Relative
• 和 Static 一樣
• 除非你有讓他移動 (left, right, top, bottom)
• 相對的出現在原本應該的位置
CSS.pptx
Fixed
• 固定在Browser視窗
• 脫離一般的排版順序
• Example: Udn的Menu bar,煩人的右下角廣告
Absolute
• 和Fixed有87%像
• 不會根據 browser視窗定位,而是用父層定位
• 若要使用,父層要加上position: relative
Display
Inline, block, inline-block
Inline
• 不會換行,只有一行
• 只有margin-bottom, margin-top不行
• 沒有width
Block
• 會把寬度加到最大
• 自動換行
Inline-block
• 外面Inline, 裏面block
• 有和Float類似的行爲
但是有問題!
CSS.pptx
Reference
• https://caniuse.com/#search=box-sizing
• https://www.html-seminar.de/box-modell-box-sizing-border-box.htm
• https://ithelp.ithome.com.tw/articles/10194997
• https://stackoverflow.com/questions/19782332/margin-stacks-on-
each-other
• https://wcc723.github.io/css/2016/06/08/css-margin-collapsing/
• http://zh-tw.learnlayout.com/box-model.html

More Related Content

PDF
spread operator vs array.concat()
PDF
LDAvis
PDF
Towards better analysis of deep convolutional neural networks
PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
PDF
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
PDF
2024 State of Marketing Report – by Hubspot
spread operator vs array.concat()
LDAvis
Towards better analysis of deep convolutional neural networks
2024 Trend Updates: What Really Works In SEO & Content Marketing
Storytelling For The Web: Integrate Storytelling in your Design Process
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
2024 State of Marketing Report – by Hubspot

CSS.pptx

Editor's Notes

  • #12: 講完盒子模型了,來講一個很重要的屬性。2006年, 菜鳥小明要自己寫網頁。他寫一個文章列表,就是一個盒子加上圖片和文章標題
  • #13: 做了寬400, 高100的東西
  • #14: 於是加上padding
  • #15: 看似幸福美滿,再繼續寫就能做出設計師要的版型?
  • #16: 可以給大家猜猜看 原本width: 400 height: 100的東西就變成這樣了!
  • #17: 要解決的話:width: 378px, height: 58
  • #19: 那舊的屬性:content-box和border-box有什麼不一樣呢
  • #30: 碰到 display : block 元素就是會換行,而 display : block 元素的寬度預設會撐到最大。 display : block 元素不管是 margin 、 padding 、 width 、 height 、 background-image 通通都可以。 要將 display : block 元素水平置中,方法是在此元素加上 margin : 0 auto , 0 可以取代為任何數字。