.demo{
position: relative;
width: 500px;
height: 300px;
line-height: 50px;
text-align: center;
color: red;
}
.demo::before{
content: "";
position: absolute;
left: 0;
top: 0;
z-index: -1; /*放在内容背后*/
width: 500px;
height: 300px;
background: url(bg.png);
background-size: cover;
opacity: 0.5; /*透明度*/
}
<div class="demo">图片半透明<br>内容不透明</div>
css设置背景图片透明度
最新推荐文章于 2023-09-09 10:29:14 发布