text-stroke 속성

text-stroke 속성은 텍스트 문자의 외곽선 색상과 두께, 즉 외곽선을 지정합니다. 속성 값으로는 외곽선의 두께와 색상을 공백으로 구분하여 지정해야 합니다.

구문

css선택자 {
  text-stroke: 외곽선 두께와 색상;
}

기본 예제

간단한 텍스트 외곽선:

html<div class="stroked-text">
  Lorem ipsum dolor sit amet
</div>
css.stroked-text {
  font-size: 48px;
  font-weight: bold;
  -webkit-text-stroke: 2px red;
  text-stroke: 2px red;
}

Результат:

외곽선만 표시

이제 텍스트 색상을 배경 색상(이 경우 흰색)과 동일하게 만듭니다. 결과적으로 외곽선만 남게 됩니다:

html<div class="stroked-text">
  Lorem ipsum dolor sit amet
</div>
css.stroked-text {
  font-size: 48px;
  font-weight: bold;
  color: white;
  -webkit-text-stroke: 2px black;
  text-stroke: 2px black;
}

Результат:

그라데이션 외곽선

background-clip 속성을 사용하여 그라데이션 외곽선을 만들어 봅시다:

html<div class="gradient-stroke">
  Lorem ipsum dolor sit amet
</div>
css.gradient-stroke {
  font-size: 42px;
  font-weight: bold;
  background: linear-gradient(to right, #ff8a00, #e52e71);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px #333;
  text-stroke: 1px #333;
}

Результат:

다중 외곽선

text-shadow를 사용한 이중 외곽선 효과:

html<div class="double-stroke">
  Lorem ipsum dolor sit amet
</div>
css.double-stroke {
  font-size: 40px;
  color: white;
  -webkit-text-stroke: 3px #000;
  text-stroke: 3px #000;
  text-shadow: 
    0 0 5px #000,
    0 0 10px #000;
}

Результат:

애니메이션 외곽선

외곽선 변경 애니메이션을 추가해 봅시다:

html<div class="animated-stroke">
  Lorem ipsum dolor sit amet
</div>
css.animated-stroke {
  font-size: 38px;
  color: white;
  -webkit-text-stroke: 1px #ff0000;
  text-stroke: 1px #ff0000;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { -webkit-text-stroke: 1px #ff0000; text-stroke: 1px #ff0000; }
  50% { -webkit-text-stroke: 3px #ff0000; text-stroke: 3px #ff0000; }
  100% { -webkit-text-stroke: 1px #ff0000; text-stroke: 1px #ff0000; }
}

Результат:

함께 보기