Свойство 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 сипаттамасы,
    ол мәтін контурінің қалыңдығын белгілейді