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

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ : ์ผ๋ ์ด๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜

by ์ฝ”ํŒŒ์นด 2022. 9. 19.
728x90

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ : ์ผ๋ ์ด๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜

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


1. HTML(PUG) ์†Œ์Šค

div.circle-wrap
    -for (var x = 1; x<=12; x++)
        div.row
        -for (var y = 1; y<=12; y++)
            div.circle

HTML ์†Œ์Šค๋Š” ๋ฐ˜๋ณต ์ž‘์—…์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— PUG๋ฅผ ์ด์šฉํ•˜๋ฉด ์ˆ˜์›”ํ•˜๊ฒŒ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„ ์†Œ์Šค๋Š” ์ด 12๊ฐœ์˜ row ํด๋ž˜์Šค๋ฅผ ๊ฐ€์ง„ div ์•ˆ์—, ๊ฐ๊ฐ 12๊ฐœ์˜ circle ํด๋ž˜์Šค๋ฅผ ๊ฐ€์ง„ div ๋ฐ•์Šค๋ฅผ ๋งŒ๋“  ๊ฒƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

2. CSS ์†Œ์Šค

body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-image: linear-gradient(45deg, #00dbde 0%, #fc00ff 100%);
}

.row {
    display: flex;
}

.row .circle {
    width: 10px;
    height: 10px;
    background: #fff;
    border-radius: 50%;
    margin: 5px 10px;
    transform-origin: top center;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: scale(1.1) rotate(0deg);
    }
    50% {
        transform: scale(0.2) rotate(180deg);
    }
    100% {
        transform: scale(1.1) rotate(360deg);
    }
}

.row:nth-child(1) .circle {
    animation-delay: 100ms;
}

.row:nth-child(2) .circle {
    animation-delay: 200ms;
}

.row:nth-child(3) .circle {
    animation-delay: 300ms;
}

.row:nth-child(4) .circle {
    animation-delay: 400ms;
}

.row:nth-child(5) .circle {
    animation-delay: 500ms;
}

.row:nth-child(6) .circle {
    animation-delay: 600ms;
}

.row:nth-child(7) .circle {
    animation-delay: 700ms;
}

.row:nth-child(8) .circle {
    animation-delay: 800ms;
}

.row:nth-child(9) .circle {
    animation-delay: 900ms;
}

.row:nth-child(10) .circle {
    animation-delay: 1000ms;
}

.row:nth-child(11) .circle {
    animation-delay: 1100ms;
}

.row:nth-child(12) .circle {
    animation-delay: 1200ms;
}

body์— ๊ทธ๋ผ๋ฐ์ด์…˜์œผ๋กœ ๋ฐฐ๊ฒฝ์ƒ‰์„ ์ฃผ๊ณ , flex๋กœ ์•„์ดํ…œ๋“ค์„ ๊ฐ€์šด๋ฐ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ circle์— ๋„ˆ๋น„, ๋†’์ด๊ฐ’์„ ๋ถ€์—ฌํ•˜๊ณ , keyframes๋ฅผ ์ƒ์„ฑํ•ด ์ค๋‹ˆ๋‹ค. ๋งˆ์ง€๋ง‰์œผ๋กœ, circle ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ฐ๊ฐ์— ์ˆœ์ฐจ์ ์œผ๋กœ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋”œ๋ ˆ์ด๋ฅผ ์ ์šฉํ•ด ์ค๋‹ˆ๋‹ค.

์œ„์˜ HTML, CSS ์†Œ์Šค๋ฅผ ํ•ฉ์น˜๋ฉด ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์™„์„ฑ๋ฉ๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•˜์ฃ ?

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

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