CSS -4. Box Model

Min Bae
3 min readMar 30, 2022

--

1.box model

provided by Zerobase Front End School

2. max-width, min-width, max-height, min-height

This just sets 제곧내!

3. margin

There are margin-bottom, margin-left, margin-right, margin-top

https://developer.mozilla.org/en-US/docs/Web/CSS/margin

3.1 margin collapsing

여러 블록요소돌의 위/아래 margin이 경우에 따라 가장 큰 그기를 가진 margin으로 결합(상쇄)되는 현상:

provided by Zerobase Front End School
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing

By adding border or padding values, you could avoid margin collapsing.

4. Padding

Has pretty much the same property as margin.
But except you can’t use negative values for padding.

https://developer.mozilla.org/en-US/docs/Web/CSS/padding

5. border-style, border-width, border-color

  • border-style:
https://developer.mozilla.org/en-US/docs/Web/CSS/border-style

5.1 border shorthand

https://developer.mozilla.org/en-US/docs/Web/CSS/border

5.2 border-radius

You can make the border rounded (like you see above)

https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius

6. box-sizing

content-box
content-box gives you the default CSS box-sizing behavior. If you set an element's width to 100 pixels, then the element's content box will be 100 pixels wide, and the width of any border or padding will be added to the final rendered width, making the element wider than 100px.

border-box
border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width. This typically makes it much easier to size elements. box-sizing: border-box is the default styling that browsers use for the <table>, <select>, and <button> elements, and for <input> elements whose type is radio, checkbox, reset, button, submit, color, or search.

= 기본이 content-box이기 때문에 width 랑 height를 부여하면 content가 그 값이되는거고 만약 box-sizing: border-box로 바꾸면 border까지 포함한 content,padding,border의 값이 부여한 값이 되버린다.

https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing

--

--

Min Bae

Korean who spent half of his life in America on a journey to become a Programmer