Come fare per - Testo ritagliato
Scopri come creare un testo ritagliato/ritagliato reattivo con CSS.
Un testo ritagliato (o testo eliminato) è un testo trasparente che appare ritagliato sopra un'immagine di sfondo:
NATURA
Nota: questo esempio non funziona in Internet Explorer o Edge.
Come creare un testo ritagliato
Passaggio 1) Aggiungi HTML:
Esempio
<div class="image-container">
<div class="text">NATURE</div>
</div>
Passaggio 2) Aggiungi CSS:
La mix-blend-mode
proprietà consente di aggiungere il testo ritagliato all'immagine. Tuttavia, non è supportato in IE o Edge:
Esempio
.image-container {
background-image: url("img_nature.jpg");
/* The image used - important! */
background-size: cover;
position: relative; /* Needed to position
the cutout text in the middle of the image */
height: 300px; /* Some
height */
}
.text {
background-color: white;
color: black;
font-size: 10vw;
/* Responsive font size */
font-weight: bold;
margin: 0 auto; /* Center the text container */
padding: 10px;
width: 50%;
text-align: center; /* Center text */
position: absolute; /* Position text */
top: 50%; /* Position text in the middle */
left: 50%; /* Position
text in the middle */
transform: translate(-50%, -50%); /* Position text in the middle */
mix-blend-mode: screen;
/* This makes the cutout text possible */
}
Se vuoi un testo contenitore nero, cambia la modalità mix-blend in "moltiplica" e il colore di sfondo in nero e il colore in bianco:
Esempio
.text {
background-color: black;
color: white;
mix-blend-mode:
multiply;
....
}