๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
CSS

CSS : ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ : ๊ผฌ๋ฆฌ๋ฅผ ํ”๋“œ๋Š” ๊ฐ•์•„์ง€

by ์ฝ”ํŒŒ์นด 2022. 8. 18.
728x90

 

๊ผฌ๋ฆฌ๋ฅผ ํ”๋“œ๋Š” ๊ฐ•์•„์ง€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ

CSS ํšจ๊ณผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ผฌ๋ฆฌ๋ฅผ ํ”๋“œ๋Š” ๊ฐ•์•„์ง€ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค์–ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

See the Pen CSS Dog by mj0614k (@mj0614k) on CodePen.

์ด๋ฒˆ์—๋Š” VSCode ๋Œ€์‹ , Codepen์„ ํ™œ์šฉํ•˜์—ฌ HTML์„ Pug๋กœ, CSS๋ฅผ SCSS๋กœ ์ž‘์—…ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. Codepen ์ž‘์—…์€ ์ž‘์—…๋ฌผ์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ๊ณ , ๊ฐ„ํŽธํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์–ด ํŽธ๋ฆฌํ•˜์ง€๋งŒ, ์ •๋ ฌ์— ์ฃผ์˜ํ•ด์•ผ ํ•˜๊ณ , ์˜ค๋ฅ˜๋ฅผ ์ฐพ๊ธฐ๊ฐ€ ํž˜๋“ค๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์›๋ณธ HTML ์†Œ์Šค์™€ CSS ์†Œ์Šค๋Š” ์•„๋ž˜์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


HTML ์†Œ์Šค

๋จผ์ €, HTML๋กœ div ๋ฐ•์Šค๋ฅผ ๋งŒ๋“ค์–ด ๊ฐ•์•„์ง€์˜ ๋ชธ์„ ์ž‘์—…ํ•ด ์ค๋‹ˆ๋‹ค. ๊ฐ•์•„์ง€์˜ ์ „์ฒด์ธ dog๋Š” body์™€ torso, head๋กœ ๋‚˜๋ˆ„์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. body๋Š” ์ด 8๊ฐœ์˜ tail, head๋Š” ears, eyes, muzzle๋กœ ์„ธ๋ถ„ํ™”ํ•˜์—ฌ ์ž‘์—…ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

HTML ์†Œ์Šค ๋ณด๊ธฐ
<div class="dog">
    <div class="dog-body">
        <div class="dog-tail">
            <div class="dog-tail">
                <div class="dog-tail">
                    <div class="dog-tail">
                        <div class="dog-tail">
                            <div class="dog-tail">
                                <div class="dog-tail">
                                    <div class="dog-tail"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="dog-torso"></div>
    <div class="dog-head">
        <div class="dog-ears">
            <div class="dog-ear"></div>
            <div class="dog-ear"></div>
        </div>
        <div class="dog-eyes">
            <div class="dog-eye"></div>
            <div class="dog-eye"></div>
        </div>
        <div class="dog-muzzle">
            <div class="dog-tongue"></div>
        </div>
    </div>
</div>

CSS ์†Œ์Šค

animation, transform, translate๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ•์•„์ง€์—๊ฒŒ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋ฅผ ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

CSS ์†Œ์Šค ๋ณด๊ธฐ
body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

html,
body {
    background: #FFE16E;
    width: 100%;
    height: 100%; 
    margin: 0;
    padding: 0;
}

*,
*:before,
*:after {
    box-sizing: border-box;
    position: relative;
}

.dog {
    width: 100px;
    height: 100px;
    z-index: 1;
}

.dog:before {
    content: "";
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.03);
    transform: translatey(-30%) scale(1.5);
}

.dog * {
    position: absolute;
}

.dog-body,
.dog-head,
.dog-torso {
    border-radius: 50%;
    background: white;
    position: absolute;
    width: 100%;
    height: 100%;
}

.dog-body {
    top: -50%;
    box-shadow: inset 0 -15px 0 0 #eaebec;
    animation: dog-body 200ms ease-in-out infinite alternate;
}

.dog-body:before {
    content: "";
    position: absolute;
    bottom: 90%;
    right: 50%;
    width: 90%;
    height: 90%;
    background: rgba(255, 255, 255, 0.4);
    border-top-left-radius: 100%;
    border-bottom-left-radius: 10%;
    border-top-right-raius: 10%;
    transform-origin: right bottom;
    animation: dog-tail-blur 200ms 33.3333333333ms ease-in-out infinite alternate both;
}

@keyframes dog-tail-blur {
    0% {
        transform: rotate(0);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: rotate(90deg);
    }
}

@keyframes dog-body {
    from {
        transform: translatex(-10%);
    }

    to {
        transform: translatex(10%);
    }
}

.dog-head {
    animation: dog-head 1800ms cubic-bezier(0.11, 0.79, 0, 0.99) infinite;
}

@keyframes dog-head {
    0% {
        transform: rotate(45deg);
    }

    33% {
        transform: rotate(-45deg);
    }

    66% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(45deg);
    }
}

.dog-torso {
    top: -20%;
    background: white;
    box-shadow: inset 0 -15px 0 0 #eaebec;
    animation: dog-torso 200ms ease-in-out infinite alternate-reverse;
}

@keyframes dog-torso {
    0% {
        transform: translatex(-5%);
    }

    100% {
        transform: tranlatex(5%);
    }
}

.dog-eyes {
    width: 60%;
    top: 55%;
    left: 20%;
    z-index: 1;
}

// &:before {  // ๊ฐ•์•„์ง€์˜ ์–ผ๊ตด ์–ผ๋ฃฉ๋ฌด๋Šฌ์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
    content: ''; // ์–ผ๋ฃฉ๋ฌด๋Šฌ๊ฐ€ ์žˆ๋Š” ๊ฐ•์•„์ง€๋„ ๊ท€์—ฝ์ง€๋งŒ, ์ €๋Š” ์ฃผ์„์ฒ˜๋ฆฌํ•˜์—ฌ ๋ฐฑ๊ตฌ๋กœ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 40px;
    background: brown;
    position: absolute;
    top: -10px;
    left: -10px;
    z-index: 0;
    border: 4px solid white;
    border-left-width: 0;
    border-borrom-width: 0;
    border-top-width: 0;
    transform: rotate(-45deg);
}

.dog-eye {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    z-index: 1;
    background: black;
}

.dog-eye:first-child {
    left: 0;
}

.dog-eye:last-child {
    right: 0;
}

.dog-muzzle { // ๊ฐ•์•„์ง€์˜ ์ฃผ๋‘ฅ์ด์ž…๋‹ˆ๋‹ค.
    width: 60%;
    left: 20%;
    height: 50%;
    border-bottom-left-radius: 100%;
    border-bottom-right-radius: 100%;
    bottom: -15%;
    background: white;
}

.dog-muzzle:before,
.dog-muzzle:after {
    content: "";
    display: block;
    position: absolute;
}

.dog-muzzle:after {
    background: black;
    width: 20px;
    height: 15px;
    bottom: 12px;
    left: calc(50% - 10px);
    border-bottom-left-radius: 60% 60%;
    border-bottom-right-radius: 60% 60%;
    border-top-left-radius: 50% 40%;
    border-top-right-radius: 50% 40%;
}

.dog-ears {
    width: 40%;
    top: 25%;
    left: 30%;
}

.dog-ear {
    bottom: -10px;
    height: 50px;
    width: 50px;
    background-color: pink;
}

.dog-ear:first-child {
    right: 100%;
    border-bottom-left-radius: 80%;
    border-top-right-radius: 80%;
    box-shadow: inset -15px 15px 0 1px white;
    transform: rotate(10deg);
}

.dog-ear:last-child {
    left: 100%;
    border-bottom-right-radius: 80%;
    border-top-left-radius: 80%;
    box-shadow: inset 15px 15px 0 0 white;
    transform: rotate(-10deg);
}

.dog-tongue {
    width: 40%;
    height: 100%;
    left: calc(50% - 20px);
    z-index: -1;
    transform-origin: center top;
}

.dog-tongue:before {
    content: "";
    position: absolute;
    left: 8px;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 40px;
    background: #fd3163;
    animation: dog-tongue-inner 100ms ease-in-out infinite alternate;
}

@keyframes dog-tongue-inner {
    from {
        transform: translatey(5%);
    }

    to {
        transform: translatey(22%);
    }
}

.dog-tail {
    width: 22px;
    height: 24.2px;
    background: white;
    bottom: 40%;
    border-radius: 11px;
    left: calc(50% - 11px);
    transform-origin: center bottom;
}

.dog-tail .dog-tail {
    animation: dog-tail-segment 200ms ease-in-out infinite alternate;
}

@keyframes dog-tail-segment {
    0% {
        transform: rotate(-10deg);
    }

    100% {
        transform: rotate(10deg);
    }
}

.dog-body>.dog-tail {
    bottom: 90%;
}

๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

728x90

๋Œ“๊ธ€

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๐Ÿฆ™

CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘