πŸ”΅ CSS - clearfix

jea_iΒ·2022λ…„ 2μ›” 7일
0

CSS

λͺ©λ‘ 보기
10/19
post-thumbnail
<body>
    <p>
        <img src="img/pic07.jpg" alt="">
        Lorem, ipsum dolor sit amet consectetur adipisicing elit. Adipisci nostrum mollitia quam voluptas molestias. Quam qui deleniti saepe omnis nesciunt quaerat, nobis temporibus, ipsa aliquam molestiae id tenetur cupiditate velit!
        <br>Minus quia at expedita iusto in eos nihil vel modi amet ratione praesentium, voluptatem corrupti! Doloribus quidem atque at tenetur, porro expedita velit totam? Temporibus deleniti debitis ex dignissimos at.
    </p>
    <div class="parent">
        <div class="child ch1">λ‚΄μš©</div>
        <div class="child ch2">λ‚΄μš©</div>
        <!-- μ˜μ—­μ‚¬λΌμ§μ„ ν•΄κ²°ν•˜κΈ° μœ„ν•΄ μ‚¬μš©λœ μš”μ†Œ (empty node, empty element)
            κ·Έλ¦Όμ΄λ‚˜ ν…μŠ€νŠΈ μ‚¬μš©μ•ˆλ¨ ;
            이거 μ“°λ©΄ float μ“Έ λ•Œ λΆ€λͺ¨μš”μ†Œμ— μ˜€λ²„ν”Œλ‘œμš° μ•ˆμ¨λ„ 됨
            κ·Έλ‹₯ 쒋은 방법은 μ•„λ‹˜..-->
        <div class="clear"></div>
    </div>
    <div class="uncle">
        <!-- ::before -->
        <div class="box">μ—‰ν΄μ˜ μžμ‹μš”μ†Œ</div>
        <!-- ::after -->
    </div>
</body>

<style>
p{
    width: 500px;
    background-color: #eee;
    line-height: 20px;
}
p>img{
    height: 200px;
    float: left;
}
.parent{
    background-color: #eee;
}
.parent>.child{
    width: 200px; height: 200px;
    float: left;
}
.parent>.ch1{background-color: #f90;}
.parent>.ch2{background-color: #f30;}
.parent>.clear{
    /* ν˜•μ œμ— 같이 float 쀬을 λ•Œ both */
    clear: both;
}
.uncle{
    height: 200px;
    background-color: #09f;
}
.uncle>.box{
    background-color: #00f;
    color: fff;
}
/* uncleμ—κ²Œ κ°€μƒμ˜ μžμ‹μš”μ†Œλ§Œλ“€κΈ° */
/* μ‹€μ œν•˜λŠ” μžμ‹μš”μ†Œ μ΄μ „μœΌλ‘œ κ°€μƒμžμ‹μ„ λ§Œλ“­λ‹ˆλ‹€. */
.uncle::before{
    display: block;
    content: 'boxμš”μ†Œ μ΄μ „μœΌλ‘œ κ°€μƒμš”μ†Œκ°€ λ§Œλ“€μ–΄μ‘ŒμŠ΅λ‹ˆλ‹€';
}

/* μ‹€μ œν•˜λŠ” μžμ‹μš”μ†Œ 이후에 κ°€μƒμžμ‹μ„ λ§Œλ“­λ‹ˆλ‹€. */
.uncle::after{
    /* λΈ”λŸ­μš”μ†Œλ‘œ μž‘λ™ν•˜κ²Œ λ©λ‹ˆλ‹€. */
    display: block;
    /* λ‚΄μš©μ΄ λ“€μ–΄κ°€λŠ” content_boxλ₯Ό λ§Œλ“€μ–΄ λ‘‘λ‹ˆλ‹€. */
    content: '';
    width: 200px;height: 40px;
    background-color: #ccc;
    margin: 0 auto;
}
</style>
profile
μ—΄μ •μ—΄μ •μ—΄μ •πŸ”₯

0개의 λŒ“κΈ€

κ΄€λ ¨ μ±„μš© 정보