了解如何使用 CSS 创建响应式剪切/挖空文本。
剪切文本(或剔除文本)是一种透明文本,显示为剪切在背景图片的顶部:
笔记:此示例不适用于 Internet Explorer 或 Edge。
<div class="image-container">
<div class="text">NATURE</div>
</div>
这个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",将背景颜色更改为黑色,将颜色更改为白色:
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!