Properti text-stroke

Properti text-stroke mengatur warna dan ketebalan outline karakter teks atau outline-nya. Sebagai nilai, properti perlu diatur dengan ketebalan outline dan warna outline dipisahkan oleh spasi.

Sintaks

cssselector {
  text-stroke: ketebalan outline dan warnanya;
}

Contoh Dasar

Outline teks sederhana:

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;
}

Результат:

Hanya Outline

Sekarang mari kita buat warna teks sama dengan warna latar belakang (dalam kasus kami putih). Hasilnya, hanya outline-nya yang tersisa:

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;
}

Результат:

Outline dengan Gradien

Mari buat outline gradien dengan menggunakan properti 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;
}

Результат:

Outline Berganda

Efek outline ganda dengan 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;
}

Результат:

Outline yang Dianimasikan

Mari tambahkan animasi perubahan outline:

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; }
}

Результат:

Lihat Juga