๐ŸฃcodeLab

๊ฐ€์ƒ์„ ํƒ์ž๋ฅผ ์‚ฌ์šฉํ•ด backgroud ๋„“์ด์™€ ๋†’์ด ์ ์šฉ

jmjm 2021. 8. 4. 11:44

๊ฐ€์ƒ์„ ํƒ์ž๋ฅผ ์‚ฌ์šฉํ•ด ์›ํ•˜๋Š” ๋„“์ด์™€ ๋†’์ด๋ฅผ calc๋กœ ๋งŒ๋“ค์–ด๋ณด์ž.

์ฐธ๊ณ ํ•œ ํ™ˆํŽ˜์ด์ง€ ์‚ผ์„ฑ๋ฐ˜๋„์ฒด

<section>section</section>
<div  class="wrap">
    <div class="inner">
        <ul>
            <li>box</li>
            <li>box</li>
            <li>box</li>
            <li>box</li>
        </ul>
    </div>
</div>
<section>section</section>
/******* reset CSS *******/
* { margin: 0; padding: 0; box-sizing: border-box; }
li { list-style: none; }

/******* custom CSS *******/
section { width: 100%; height: 150px; background: #e9e9e9; }
.wrap { position: relative; padding: 50px 0; }
/* wrap::before๋ฅผ ์ด์šฉํ•˜์—ฌ background-color๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค. */
.wrap::before {
    display: block;
    content: 'beforeBG';
    width: 100%;
    height: calc(100% - 150px);
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: -1;
}
.inner { position: relative; max-width: 800px; margin: auto; }
.inner ul::after { display: block; content: ''; clear: both; }
.inner ul li:not(:first-of-type) { float: left; width: 32%; margin-left: 2%; height: 200px; background: yellowgreen; }
.inner ul li:nth-of-type(2) { margin-left: 0; }
.inner ul li:first-of-type { width: 80%; height: 200px; margin: 0 auto 20px; background: gold; }

ํŒŒ๋ž‘์ƒ‰(bottom: 0)์„ ๊ธฐ์ค€์œผ๋กœ ์œ„์—์„œ 150px ๋–จ์–ด์ง„ ๊ณณ์— before์ด ์ ์šฉ๋œ๋‹ค.