css中给文字加阴影使其在文字颜色之下
vue项目中有个标题需要渐变色并加阴影,单纯使用text-shadow
text-shadow: 7px 6px 6px rgba(6,0,1,0.66);
background: linear-gradient(0deg, #EAFFFD 0%, #68FFEF 100%);
-webkit-background-clip: text;
会使阴影层覆盖在文字之上,渐变的背景被阴影覆盖。
解决问题只需要加好层级关系。
<div class="title" text="社区平台">社区平台</div>
.title{
position: absolute;
margin-left: 456px;
margin-top: 19px;
font-size: 40px;
font-family: Source Han Sans SC;
text-shadow: 7px 6px 6px rgba(6,0,1,0.66);
font-weight: 600;
}
.title::before {
content: attr(text);
position: absolute;
z-index: 10;
color: #FEFEFE;
// 渐变样式
background: linear-gradient(0deg, #EAFFFD 0%, #68FFEF 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
// 去除继承父级样式
text-shadow: none;
}
这样就能实现阴影在字体之下,实测有用。