Client/CSS

[CSS] CSS ๊ธฐ๋ณธ ๋ฐ•์Šค ๋ชจ๋ธ(Box Model)

meeeeejin 2020. 6. 9. 02:06

CSS ๋ฐ•์Šค ๋ชจ๋ธ(Box Model)

ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋งˆ์šฐ์Šค ์šฐํด๋ฆญ -> ๊ฒ€์‚ฌ ๋˜๋Š” Ctrl + Shift + I ๋ฅผ ๋ˆŒ๋Ÿฌ์„œ ๋‚˜์˜ค๋Š” ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ Elements ํƒญ์„ ๋ˆ„๋ฅด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐ•์Šค ๋ชจ๋ธ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

 

  • content ์˜์—ญ

    : ๊ธ€, ์ด๋ฏธ์ง€, ๋น„๋””์˜ค ๋“ฑ ์‹ค์ œ ๋‚ด์šฉ์„ ํฌํ•จํ•˜๋Š” ์˜์—ญ

  • padding ์˜์—ญ

    : ์•ˆ์ชฝ ์—ฌ๋ฐฑ; border์™€ content ์‚ฌ์ด์˜ ์˜์—ญ

  • border ์˜์—ญ

    : ํ…Œ๋‘๋ฆฌ

  • margin ์˜์—ญ

    : ๋ฐ”๊นฅ์ชฝ ์—ฌ๋ฐฑ; ๋‹ค๋ฅธ ํƒœ๊ทธ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ

์ด๋•Œ padding, border, margin์€ width์— ํฌํ•จ๋˜์ง€ ์•Š๊ธฐ๋•Œ๋ฌธ์— ์š”์†Œ์˜ ์ „์ฒด width๋ฅผ ๊ณ„์‚ฐํ•˜๋ ค๋ฉด ์ด๋ฅผ ํฌํ•จ์‹œ์ผœ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. 

 

์˜ˆ์ œ: width ๊ตฌํ•˜๊ธฐ

1
2
3
4
5
6
div {
    width: 320px;
    padding: 10px;
    border: 5px solid gray;
    margin: 0;
}
cs

์œ„์™€ ๊ฐ™์€ div ์š”์†Œ๊ฐ€ ์žˆ์„ ๋•Œ ์ด ์š”์†Œ์˜ total width๋ฅผ ๊ตฌํ•˜๋Š” ์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

total width

=> 320px (width)

      + 10px (left padding) + 10px (right padding)

      + 5px (left border) + 5px (right border)

      + 0px (margin)

     = 350px

 

 

728x90