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

[CSS] SCSS ์‹ค์Šต01 : ์›€์ง์ด๋Š” ๊ฐ•์•„์ง€ ์ผ๋Ÿฌ์ŠคํŠธ ๐Ÿถ

by _ํ† ๋งคํ†  2022. 8. 19.
728x90

SCSS ์‹ค์Šต01 : ๐Ÿถ ์›€์ง์ด๋Š” ๊ฐ•์•„์ง€ ๐Ÿถ

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” css ์ข…๋ฅ˜ ์ค‘ ํ•˜๋‚˜์ธ ์ง€๋‚œ ์‹œ๊ฐ„์— ๋ฐฐ์› ๋˜ SCSS์–ธ์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ ์‹ค์Šต์„ ํ•ด๋ด…์‹œ๋‹ค!

dog

๐Ÿถ HTML ๐Ÿถ

! point!
๋ถ€๋ชจ์ž์‹ํ˜•์ œ ์š”์†Œ์— ๋งž๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ •๋ ฌํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค! ์ฝ”๋“œ๋ฅผ ์งค ๋• ํ•ญ์ƒ ์ฝ”๋“œ ์ •๋ ฌ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”!

<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="dogtongue"></div>
      </div>
    </div>
  </div>

๐Ÿถ SCSS ๐Ÿถ

SCSS๋ฅผ ์ด์šฉํ•˜์—ฌ ์Šคํƒ€์ผ ์†์„ฑ์„ ์ •ํ•ด์ค๋‹ˆ๋‹ค.

$dog-width: 100px;
$interval: 200ms;
$color-gray: #eaebec;
$easing: ease-in-out;

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

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

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

// dog
.dog {
    width: $dog-width;
    height: $dog-width;
    z-index: 1;
    
    &:before {
        content: '';
        display: block;
        position: absolute;
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background: rgba(black, 0.03);
        transform: translatey(-30%) scale(1.5);
    }
    
    * {
        position: absolute;
    }
}

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

// dog-body
.dog-body {
    top: -50%;
    box-shadow: inset 0 -15px 0 0 $color-gray;
    animation: dog-body $interval $easing infinite alternate;
    
    &:before {
        content:'';
        position: absolute;
        bottom: 90%;
        right: 50%;
        width: 90%;
        height: 90%;
        background: rgba(white, 0.4);
    border-top-left-radius: 100%;
    border-bottom-left-radius: 10%;
    border-top-right-radius: 10%;
    transform-origin: right bottom;
    animation: dog-tail-blur $interval $interval / 6 $easing 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%);} // 0%์™€ ๋˜‘๊ฐ™์ด ์‹œ์ž‘์„ ์˜๋ฏธํ•œ๋‹ค.
    to {transform: translatex(10%);}  //100%์™€ ๋˜‘๊ฐ™์ด ๋งˆ์ง€๋ง‰์„ ์˜๋ฏธํ•œ๋‹ค.
    }
}

// dog-head
.dog-head {
    animation: dog-head $interval * 9 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
.dog-torso {
    top: -20%;
    background: white;
    box-shadow: inset 0 -15px 0 0 $color-gray;
    animation: dog-torso $interval $easing infinite alternate-reverse;
    
    @keyframes dog-torso {
    0% {transform: translatex(-5%);}
    100% {transform: translatex(5%);}
    }
}

// dog-eyes
.dog-eyes {
    width: 60%;
    top: 55%;
    left: 20%;
    z-index: 1;
    
    &:before {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 40px;
    background: orange;
    position: absolute;
    top: -10px;
    left: -10px;
    z-index: 0;
    border: 4px solid white;
    border-left-width: 0;
    border-bottom-width: 0;
    border-top-width: 0;
    transform: rotate(-45deg);
    }
}
.dog-eye {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #000;
    z-index: 1;
    
    &:first-child {
    left: 0;
    }
    &:last-child {
    right: 0;
    }
}

// dog-muzzle
.dog-muzzle {
    width: 60%;
    left: 20%;
    height: 50%;
    border-bottom-left-radius: 100%;
    border-bottom-right-radius: 100%;
    bottom: -15%;
    background: white;
    
    &:before, &:after {
    content:'';
    display: block;
    position: absolute
    }
    
    &:before {
    width: 6px;
    height: 20px;
    bottom: 0;
    background: $color-gray;
    left: calc(50% - 3px);
    }
    
    &: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
.dog-ears {
    width: 40%;
    top: 25%;
    left: 30%;
    
}
.dog-ear {
    bottom: -10px;
    height: 50px;
    width: 50px;
    background: pink;
    
    &: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);
    }
    &: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);
    }
}

// dogtongue
.dogtongue {
    width: 40%;
    height: 100%;
    left: calc(50% - 20px);
    z-index: -1;
    transform-origin: center top;
    
    &:before {
    content: '';
    position: absolute;
    left: 8px;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 40px;
    background: #fd3163;
    animation: dog-tongue-inner $interval / 2 $easing infinite alternate;
    
    @keyframes dog-tongue-inner {
        from {transform: translatey(5%);}
        to {transform: translatey(22%);}
    }
    }
}

// dog-tail
.dog-tail {
    $tail-width: 22px;
    width: $tail-width;
    height: $tail-width * 1.1;
    background: white;
    bottom: 40%;
    border-radius: $tail-width / 2; //bdrs
    left: calc(50% - #{$tail-width / 2});
    transform-origin: center bottom;
    
    .dog-tail {
        animation: dog-tail-segment $interval $easing infinite alternate;

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

.dog-body > .dog-tail {
    bottom: 90%;
}
โœ๏ธ CSS ๋ฌธ๋ฒ•์œผ๋กœ ๋ณด๊ธฐ
body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

html, body {
  background: orange;
  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-radius: 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: translatex(5%);
  }
}

.dog-eyes {
  width: 60%;
  top: 55%;
  left: 20%;
  z-index: 1;
}
.dog-eyes:before {
  content: "";
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  background: orange;
  position: absolute;
  top: -10px;
  left: -10px;
  z-index: 0;
  border: 4px solid white;
  border-left-width: 0;
  border-bottom-width: 0;
  border-top-width: 0;
  transform: rotate(-45deg);
}

.dog-eye {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #000;
  z-index: 1;
}
.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:before {
  width: 6px;
  height: 20px;
  bottom: 0;
  background: #eaebec;
  left: calc(50% - 3px);
}
.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: 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);
}

.dogtongue {
  width: 40%;
  height: 100%;
  left: calc(50% - 20px);
  z-index: -1;
  transform-origin: center top;
}
.dogtongue: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%;
}

! point!
๊ฐ€์ƒ์š”์†Œ์™€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์†์„ฑ์„ ์ž˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค! ๊ฐ ์–ด๋–ค ํšจ๊ณผ์˜ ์†์„ฑ์ธ์ง€ ์ž˜ ์•Œ์•„๋‘์„ธ์š”!


๐Ÿถ ์‹ค์Šต ๊ฒฐ๊ณผ ๋ณด๊ธฐ ๐Ÿถ

! ๊ฒฐ๊ณผ ๋ณด๊ธฐ ์ „ ! ์•„๋ž˜์˜ html ์ฝ”๋“œ๋Š” Pug๋ฌธ์ด๋ฏ€๋กœ HTML๋ฌธ๋ฒ•์€ ์œ„์˜ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค!

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css