gpt4 book ai didi

带有背景图像的 CSS 插入文本阴影

转载 作者:太空宇宙 更新时间:2023-11-04 08:13:23 25 4
gpt4 key购买 nike

是否可以让文字同时带有背景图片和内阴影?

div{   
position:fixed;
z-index: 2;
color: white; /* Fallback: assume this color ON TOP of image */
background: url('https://placekitten.com/g/500/500') repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 100px;
font-weight: 800;
text-transform: uppercase;
text-shadow: 2px 3px 8px rgba(59, 37, 17, 0.35) inset;
}
<div>
CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>

最佳答案

使用 CSS 过滤器属性,您可以添加轮廓为任何形状的阴影:

div{   
position:fixed;
z-index: 2;
color: white; /* Fallback: assume this color ON TOP of image */
background: url('https://placekitten.com/g/500/500') repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 100px;
font-weight: 800;
text-transform: uppercase;
text-shadow: 2px 3px 8px rgba(59, 37, 17, 0.35) inset;
filter: drop-shadow( 10px 10px 10px #888 );
}
<div>
CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>

所有主流浏览器现在都支持基本的过滤器! http://caniuse.com/#feat=css-filters

对于嵌入阴影

嵌入阴影需要一些技巧。

我的方法是直接在第一个 div 之上添加另一个具有透明文本不透明度的 div。然后我们使用文本阴影 hack 使其看起来像是嵌入的。

.regular {
position:fixed;
z-index: -1
color: white; /* Fallback: assume this color ON TOP of image */
background: url('https://placekitten.com/g/500/500') repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 100px;
font-weight: 800;
text-transform: uppercase;
text-shadow: 2px 3px 8px rgba(59, 37, 17, 0.35) inset;
}
.overlay {
position:fixed;
z-index: 10;
color: transparent;
font-size: 100px;
font-weight: 800;
text-transform: uppercase;
text-shadow: 2px 2px 3px rgba(255,255,255,0.5);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
}
<div class="regular">
CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>
<div class="overlay">
CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>

关于带有背景图像的 CSS 插入文本阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46085791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com