๐Ÿ”ฅHTML ๋ฐ CSS๋ฅผ ์‚ฌ์šฉํ•œ ์ด๋ฏธ์ง€ ํ˜ธ๋ฒ„ ํ…์ŠคํŠธ ์˜ค๋ฒ„๋ ˆ์ด ํšจ๊ณผ

7243 ๋‹จ์–ด webdevcssbeginnershtml
์ด ๊ฒŒ์‹œ๋ฌผ์—์„œ๋Š” HTML ๋ฐ CSS๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•„๋ฆ„๋‹ค์šด โค๏ธ ์ด๋ฏธ์ง€ ํ˜ธ๋ฒ„ ํ…์ŠคํŠธ ์˜ค๋ฒ„๋ ˆ์ด ํšจ๊ณผ๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด ์ž์Šต์„œ์—์„œ๋Š” HTML ๋ฐ CSS ์†์„ฑ์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ์ง€์‹์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.



โœจ HTML ์“ฐ๊ธฐ



์šฐ๋ฆฌ์˜ HTML ์ฝ”๋“œ๋Š” ๋งˆํฌ์—…์„ ์œ„ํ•œ ๋ช‡ ์ค„์— ๋ถˆ๊ณผํ•ฉ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    <div class="image">
        <img class="image__img" src="https://cdn.pixabay.com/photo/2017/12/15/13/51/polynesia-3021072__340.jpg"
            alt="Bricks">
        <div class="image__overlay">
            <div class="image__title">Ocean</div>
            <p class="image__description">
                Enjoy the blue color of ocean.
            </p>
        </div>
    </div>


์—ฌ๊ธฐ์— ๋ชจ๋“  ์š”์†Œ์˜ ์ƒ์œ„ ๐Ÿ‘จโ€๐Ÿ‘ง์ธ div ์ด๋ฏธ์ง€๊ฐ€ ์žˆ๋Š” class๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด div ๋‚ด๋ถ€์— ์ด๋ฏธ์ง€๋ฅผ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•œ img ํƒœ๊ทธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ์•„๋ž˜์—๋Š” div image__overlay๊ฐ€ ์žˆ๋Š” class๊ฐ€ ์žˆ์œผ๋ฉฐ ์ด๋ฏธ์ง€ ์œ„๋กœ ๋งˆ์šฐ์Šค๋ฅผ ๊ฐ€์ ธ๊ฐ€๋ฉด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์ด ์•ˆ์— ์˜ค๋ฒ„๋ ˆ์ด์— ํ‘œ์‹œํ•˜๋ ค๋Š” ์ด๋ฏธ์ง€์™€ ๊ด€๋ จ๋œ ํ…์ŠคํŠธ๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿคฉ CSS๋กœ ์‹ค์ œ ํšจ๊ณผ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



์—ฌ๊ธฐ์—์„œ ๋จผ์ € img ํƒœ๊ทธ์— ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ณธ ์Šคํƒ€์ผ์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. width ๋ฐ height ์†์„ฑ์„ ๋งŒ๋“ค์–ด ๋ถ€๋ชจ์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ „์ฒด ํฌ๊ธฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

.image__img {
    display: block;
    width: 100%;
    height: 100%;
    background-size: cover;
}


๋ถ€๋ชจ ์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆposition์˜ ์†์„ฑrelative๊ณผ ์˜ค๋ฒ„๋ ˆ์ด์˜ ์†์„ฑ์„ absolute๋กœ ๋งŒ๋“ค์–ด
์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆ์˜ ์น˜์ˆ˜๋ฅผ ์ค€์ˆ˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์˜ค๋ฒ„๋ ˆ์ด์˜ top ๋ฐ left ์†์„ฑ์„ 0 ์œผ๋กœ ๋งŒ๋“ค์–ด ์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆ์˜ ์™ผ์ชฝ ์ƒ๋‹จ์—์„œ ๋ฐ”๋กœ ์‹œ์ž‘ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. width ๋ฐ height๋ฅผ 100%๋กœ ๋งŒ๋“ค์–ด ์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆ์˜ ์ „์ฒด ๋„ˆ๋น„๋ฅผ ์ฑ„์šฐ๊ณ  ์™„์ „ํžˆ ๋ฎ์„ ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์ด์ œ ์ด ์˜ค๋ฒ„๋ ˆ์ด์˜ background ๋ถˆํˆฌ๋ช…๋„๊ฐ€ ๊ฑฐ์˜ ์—†๋Š” ๊ฒ€์€์ƒ‰์œผ๋กœ ๋งŒ๋“ค์–ด ๊ธฐ๋ณธ ์ด๋ฏธ์ง€๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ํ…์ŠคํŠธ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€CSS๋ฅผ ์ถ”๊ฐ€ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ถ€๋“œ๋Ÿฌ์šด ๋Š๋‚Œ์ด ๋“ค๋„๋ก ์˜ค๋ฒ„๋ ˆ์ด์— transition๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

.image {
    position: relative;
    width: 30%;
}

.image__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    color: #ffffff;
    font-family: 'Quicksand', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.25s;
}


์ด์ œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๐Ÿ›Ž๏ธ ๋ถ€๋ถ„์„ ๊ทธ๋Œ€๋กœ ๋‘๋ฉด ์ฒ˜์Œ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€์— ์˜ค๋ฒ„๋ ˆ์ด๊ฐ€ ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋ฏธ์ง€ ์œ„์˜ hover์—๋งŒ ๋‚˜ํƒ€๋‚˜๊ธฐ๋ฅผ ์›ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ฒ˜์Œ์—๋Š” ์˜ค๋ฒ„๋ ˆ์ดopacity๋ฅผ 0์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ์ผœ์งhover์„ 1๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

// at start
.image__overlay{
      opacity: 0;
}

// on hover
.image__overlay:hover {
    opacity: 1;
}


๊ทธ๊ฒŒ ๋‹ค์•ผ ์ด๋ฏธ์ง€ ํ˜ธ๋ฒ„ ํ…์ŠคํŠธ ์˜ค๋ฒ„๋ ˆ์ด ํšจ๊ณผ ๐Ÿ’ช๋ฅผ ์™„์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
์ด ์˜ค๋ฒ„๋ ˆ์ด ํšจ๊ณผ๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ํ๋ฆฟํ•œ ์˜ค๋ฒ„๋ ˆ์ด ๋˜๋Š” ๋‹จ์ƒ‰ ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐ„๋‹จํ•œ ํด๋ž˜์Šค๋ฅผ CSS ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•œ ๋‹ค์Œ HTML์˜ ์˜ค๋ฒ„๋ ˆ์ด div์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

.image__overlay--blur {
    backdrop-filter: blur(5px);
}

.image__overlay--solid {
    background: #c51f5d;
}


์ €๊ฒƒ๊ณผ ๊ฐ™์ด ์‰ฌ์šด. ๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ๋Š” ์ด๋Ÿฌํ•œ ์ž‘์€ ์ฝ”๋“œ๋กœ ์„ธ ๊ฐ€์ง€ ๋ฉ‹์ง„ CSS ํ˜ธ๋ฒ„ ํšจ๊ณผ๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด ๋„์›€์ด ๋˜๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค ๐Ÿ˜‡.

์ฒซ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ž˜๋˜๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์ด ๊ฒŒ์‹œ๋ฌผ์ด ๋งˆ์Œ์— ๋“ค๋ฉด ๋‹ค์Œ์—์„œ ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋‚ด ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ ๋ฐฉ๋ฌธ: satishnaikawadi.me

  • ์ฝ์–ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ