Proprietà text-stroke
La proprietà text-stroke imposta il colore e lo spessore del contorno
dei caratteri del testo o la sua delineazione. Come
valore della proprietà è necessario specificare
lo spessore del contorno e, separato da uno spazio, il colore del contorno.
Sintassi
selettore {
text-stroke: spessore contorno e suo colore;
}
Esempio base
Semplice contorno del testo:
<div class="stroked-text">
Lorem ipsum dolor sit amet
</div>
.stroked-text {
font-size: 48px;
font-weight: bold;
-webkit-text-stroke: 2px red;
text-stroke: 2px red;
}
:
Solo contorno
Ora rendiamo il colore del testo coincidente con il colore di sfondo (nel nostro caso bianco). Di conseguenza, rimarrà solo il contorno:
<div class="stroked-text">
Lorem ipsum dolor sit amet
</div>
.stroked-text {
font-size: 48px;
font-weight: bold;
color: white;
-webkit-text-stroke: 2px black;
text-stroke: 2px black;
}
:
Contorno con gradiente
Creiamo un contorno sfumato
utilizzando la proprietà background-clip:
<div class="gradient-stroke">
Lorem ipsum dolor sit amet
</div>
.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;
}
:
Contorno multiplo
Effetto doppio contorno con text-shadow:
<div class="double-stroke">
Lorem ipsum dolor sit amet
</div>
.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;
}
:
Contorno animato
Aggiungiamo un'animazione che modifica il contorno:
<div class="animated-stroke">
Lorem ipsum dolor sit amet
</div>
.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; }
}
:
Vedi anche
-
la proprietà
text-fill-color,
che imposta il colore di riempimento dei caratteri del testo -
la proprietà
text-stroke-color,
che imposta il colore del contorno del testo -
la proprietà
text-stroke-width,
che imposta lo spessore del contorno del testo