-webkit-background-clip: text
相应的IE回退功能对剪辑效果很好,但每次我都尝试使用
display: inline-block
position: absolute
文本立即消失。
body {
margin: 1rem;
}
.box {
height: calc(100vh - 2rem);
border: 1px solid;
background-image: url(http://lorempixel.com/1280/720/);
-webkit-background-clip: text;
}
.align {
/* to right-align the text box */
text-align: right;
/* uncomment below to see the issue */
/* display: inline-block; */
}
.title {
/* Duplicated here for Safari */
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
color: yellow;
margin: 0;
font: bold 6rem/1 sans-serif;
text-transform: uppercase;
text-align: center;
}
<article class="box">
<div class="align">
<h1 class="title">The Title</h1>
</article>
我创造了
a Codepen with an example
. 如果您取消注释
.align
类或尝试将其垂直居中
位置:绝对位置
transform
例如,文本消失。
我肯定我错过了一些简单的东西,任何建议都非常感谢!