BAGAIMANA - Potongan Teks
Pelajari cara membuat teks cutout/knockout responsif dengan CSS.
Teks potongan (atau teks knockout) adalah teks tembus pandang yang muncul terpotong di atas gambar latar belakang:
ALAM
Catatan: Contoh ini tidak berfungsi di Internet Explorer atau Edge.
Cara Membuat Potongan Teks
Langkah 1) Tambahkan HTML:
Contoh
<div class="image-container">
<div class="text">NATURE</div>
</div>
Langkah 2) Tambahkan CSS:
Properti mix-blend-mode
memungkinkan untuk menambahkan teks potongan ke gambar. Namun, itu tidak didukung di IE atau Edge:
Contoh
.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 */
}
Jika Anda menginginkan teks kontainer hitam, ubah mix-blend-mode menjadi "multiply" dan warna latar belakang menjadi hitam, dan warna menjadi putih:
Contoh
.text {
background-color: black;
color: white;
mix-blend-mode:
multiply;
....
}