方法-切り抜きテキスト
CSSを使用してレスポンシブカットアウト/ノックアウトテキストを作成する方法を学びます。
カットアウトテキスト(またはノックアウトテキスト)は、背景画像の上にカットアウトされて表示されるシースルーテキストです。
自然
注:この例は、InternetExplorerまたはEdgeでは機能しません。
切り抜きテキストを作成する方法
ステップ1)HTMLを追加します。
例
<div class="image-container">
<div class="text">NATURE</div>
</div>
ステップ2)CSSを追加します。
このmix-blend-mode
プロパティを使用すると、切り抜きテキストを画像に追加できます。ただし、IEまたはEdgeではサポートされていません。
例
.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 */
}
黒のコンテナテキストが必要な場合は、mix-blend-modeを「multiply」に、background-colorを黒に、colorを白に変更します。
例
.text {
background-color: black;
color: white;
mix-blend-mode:
multiply;
....
}