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

[CSS] ํ…์ŠคํŠธ๊ฐ€ ์„œ์„œํžˆ ๊ทธ๋ ค์ง€๋Š” SVG ์• ๋‹ˆ๋ฉ”์ด์…˜

by ์ฝ”๋”ฉ๊ณต์ฑ… 2022. 9. 8.
๋ฐ˜์‘ํ˜•

SVG ํ…์ŠคํŠธ ์• ๋‹ˆ๋ฉ”์ด์…˜

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ํ…์ŠคํŠธ๊ฐ€ ์„œ์„œํžˆ ๊ทธ๋ ค์ง€๋Š” ํšจ๊ณผ์˜ SVG ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค์–ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. <svg> ํƒœ๊ทธ๊ฐ€ ์‚ฌ์šฉ๋œ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

HTML ์†Œ์Šค

<svg viewBox="0 0 1320 300">
    <text x="50%" y="50%" dy="40px" text-anchor="middle">์ฝ”๋”ฉ๊ณต์ฑ…</text>
</svg>

CSS ์†Œ์Šค

@font-face {
    font-family: 'Jalnan';
    font-weight: normal;
    font-style: normal;
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/goodchoice/Jalnan.eot');
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/goodchoice/Jalnan.eot?#iefix') format('embedded-opentype'),
        url('https://cdn.jsdelivr.net/gh/webfontworld/goodchoice/Jalnan.woff2') format('woff2'),
        url('https://cdn.jsdelivr.net/gh/webfontworld/goodchoice/Jalnan.woff') format('woff'),
        url('https://cdn.jsdelivr.net/gh/webfontworld/goodchoice/Jalnan.ttf') format("truetype");
    font-display: swap;
}

body {
  background-color: #FFEBEE;
}
svg {
  font-family: 'Jalnan';
  font-size: 140px;
  position: absolute;
  width: 100%;
  height: 100%;
  text-transform: uppercase;
  animation: stroke 5s infinite alternate;
  fill: rgba(72,138,204,1);
}
@keyframes stroke {
  0% {
    stroke-dashoffset: 25%;
    stroke-dasharray: 0 50%;
    fill: rgba(72,138,204,0);
    stroke: rgba(54,95,160,1);
    stroke-width: 2;
  }
  70% {
    fill: rgba(72,138,204,0);
    stroke: rgba(54,95,160,1);
  }
  80% {
    fill: rgba(72,138,204,0);
    stroke: rgba(54,95,160,1);
  }
  100% {
    stroke-dashoffset: -25%;
    stroke-dasharray: 50% 0;
    fill: rgba(72,138,204,1);
    stroke: rgba(54,95,160,0);
    stroke-width: 0;
  }
}

์ฝ”๋“œํŽœ ๊ฒฐ๊ณผ

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€


Reference Book

JavaScript
HTML
CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.