Jak to zrobić — tekst wycinany
Dowiedz się, jak utworzyć responsywny tekst wycinany/odcinany za pomocą CSS.
Tekst wycinany (lub tekst wycinany) to przezroczysty tekst, który pojawia się wycięty na górze obrazu tła:
NATURA
Uwaga: ten przykład nie działa w przeglądarce Internet Explorer ani Edge.
Jak stworzyć tekst wycinany
Krok 1) Dodaj kod HTML:
Przykład
<div class="image-container">
<div class="text">NATURE</div>
</div>
Krok 2) Dodaj CSS:
Właściwość mix-blend-mode
umożliwia dodanie tekstu wycinanego do obrazu. Jednak nie jest obsługiwany w IE ani Edge:
Przykład
.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 */
}
Jeśli chcesz mieć czarny tekst kontenera, zmień tryb mieszania na „pomnóż”, kolor tła na czarny i kolor na biały:
Przykład
.text {
background-color: black;
color: white;
mix-blend-mode:
multiply;
....
}