inline-block

๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•  ๋•Œ float ์™ธ์— ๋งŽ์ด ์“ฐ๋Š” ๊ฒƒ์ค‘ ํ•˜๋‚˜์ธ inline-block

display : block (ํ•œํ–‰์„ ์ „๋ถ€ ์ฐจ์ง€)

display : inline-block (๋‚ด ํฌ๊ธฐ๋งŒํผ ์ฐจ์ง€)

๊ฐ€๋กœ๋กœ ์ •๋ ฌํ•  ๋•Œ float : left ์ด๊ฒƒ๋งŒ ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค.

display : inline-block์„ ์‚ฌ์šฉํ•ด๋ด…์‹œ๋‹ค.

<div class="container">
    <div class="header"></div>
    <div class="left"></div><div class="right"></div> 
    //์ด๋Ÿฐ์‹์œผ๋กœ ๊ณต๋ฐฑ์„ ์—†์• ์ค˜์•ผ ํ•œ๋‹ค.
    
    <div class="footer"></div>
</div>
 ํ˜น์€ 
<div class="container">
    <div>
       <div class="left"></div><!--
    --><div class="right"></div>
    </div>
</div>
main.css
.left{
    width: 30%;
    height: 400px;
    background: cadetblue;
    display: inline-block;
}
.right{
    width: 70%;
    height: 400px;
    background: coral;
    display: inline-block;

}

์œ„์˜ ์ฝ”๋“œ๋Š” ๋ฐ•์Šค๋ฅผ ๋งŒ๋“ค์–ด ์™ผ์ชฝ์œผ๋กœ ์ •๋ ฌ์‹œํ‚ค๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

display ์†์„ฑ๋งŒ inline-block์œผ๋กœ ์กฐ์ •ํ•˜๋ฉด ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

inline- block์€ "๋‚ด ํญ๊ณผ ๋†’์ด๋งŒํผ ์ž๋ฆฌ์ฐจ์ง€ํ•˜๊ฒŒ ํ•ด์ฃผ์„ธ์š”~" ๋ผ๋Š” ๋œป์ž…๋‹ˆ๋‹ค.

๊ฐ„ํŽธํ•˜์ง€๋งŒ <ํƒœ๊ทธ> ์‚ฌ์ด์— ์ŠคํŽ˜์ด์Šค๋ฐ” ๊ณต๋ฐฑ์ด ์žˆ๋‹ค๋ฉด ๊ทธ๋Œ€๋กœ ๋ณด์—ฌ์ฃผ๊ธฐ ๋•Œ๋ฌธ์—

๊ฐ€๋กœ๋กœ ์ •๋ ฌํ•˜๋ ค๋ฉด ํƒœ๊ทธ ์‚ฌ์ด์˜ ๊ณต๋ฐฑ๋„ ์ œ๊ฑฐํ•ด์ค˜์•ผํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฐ๊ฒŒ ๊ท€์ฐฎ์Šต๋‹ˆ๋‹ค float ์“ฐ์…ˆ

์ฃผ์„์€ ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

HTML ์ฝ”๋“œ๋Š” <!-- --> ์ด๊ฒŒ ์ฃผ์„์ฒ˜๋ฆฌํ•˜๋Š” ์ฝ”๋“œ์ด๋ฉฐ

์ด ์‚ฌ์ด์— ์ฝ”๋“œ๋ฅผ ์ง‘์–ด๋„ฃ์œผ๋ฉด ์‹คํ–‰๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๊ทธ๋ž˜๋„ ๋”๋Ÿฌ์›Œ๋ณด์ž…๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ๋ฐฉ์‹

  1. left์™€ right ์‚ฌ์ด์˜ ์ฃผ์„์ฒ˜๋ฆฌ ํ˜น์€ ๊ณต๋ฐฑ์ œ๊ฑฐ

  2. ๋ถ€๋ชจ div์— font-size : 0

<div class="container" style="font-size: 0px">
    <div class="header"></div>
    <div class="left" style="font-size: 20px; vertical-align: top;">asd</div><div class="right"></div>
    <div class="footer"></div>
</div>

font-size ์†์„ฑ์€ inherit ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์•ˆ์— ์žˆ๋Š” <div>์™€ ๊ทธ ์‚ฌ์ด์— ์žˆ๋Š” ๊ณต๋ฐฑ๋„ font-size๊ฐ€ 0px์ด ๋ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฌ๋ฉด ํ•ด๊ฒฐ์ธ๋ฐ HTML์ด ๊นจ๋—ํ•ด์งˆ์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ CSS๊ฐ€ ๋”๋Ÿฌ์›Œ์งˆ ์ˆ˜ ์žˆ๊ฒ ๊ตฐ์š”.

๋‘˜ ์ค‘์— ๋œ ๋”๋Ÿฌ์›Œ๋ณด์ด๋Š” ๋ฐฉ๋ฒ•์„ ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๐ŸŽˆ. baseline์ด ์˜†์— ์กด์žฌํ•˜๋ฉด display : inline-block ์š”์†Œ๋“ค์ด baseline ์œ„์— ์˜ค๋ ค๊ณ  ํ•จ > vertical-align: top์†์„ฑ ์œผ๋กœ ํ•ด๊ฒฐ

โœจ ๊ณผ์ œ. ๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ ๊ธ€๋ชฉ๋ก ๋งŒ๋“ค์–ด๋ณด๊ธฐ (blog1.html ํŒŒ์ผ)์ƒ์„ฑ

Last updated