Својство 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; }
}

Результат:

Погледајте такође

  • својство text-fill-color,
    које поставља боју испуне слововима текста
  • својство text-stroke-color,
    које поставља боју контура текста
  • својство text-stroke-width,
    које поставља дебљину контура текста