您当前的位置:首页>HTML&CSS>CSS实现虚化透明背景图片效果 网站首页HTML&CSS
CSS实现虚化透明背景图片效果
发布时间:June 8, 2017 编辑:晓宇 阅读:(5117)
项目中经常会用到背景图上放一些文字介绍,这里介绍两种技术来实现背景图片透明,文字不透明效果,记录一下,方便日后使用。
1.毛玻璃效果:背景图 + 伪类 + flite:blur(3px)
.demo1{ width: 500px; height: 300px; line-height: 50px; text-align: center; } .demo1:before{ background: url(http://www.fanfanyu.cn/upload/image/20170207/9cefd9e0-486d-4910-ba3a-c984247f09a7.png) no-repeat; background-size: cover; width: 500px; height: 300px; content: ""; position: absolute; top: 0; left: 0; z-index: -1;/*-1 可以当背景*/ -webkit-filter: blur(3px); filter: blur(3px); } <div class="demo1">晓宇个人博客<br/>背景图半透明,文字不透明<br/>方法:背景图+ filter:blur</div>
2.半透明效果:背景图 + 定位 + background:rgba(255,255,255,0.3)
.demo2-bg{ background: url(http://www.fanfanyu.cn/upload/image/20170207/9cefd9e0-486d-4910-ba3a-c984247f09a7.png) no-repeat; background-size: cover; width: 500px; height: 300px; position: relative; } .demo2{ position: absolute; left: 0; right: 0; top: 0; bottom: 0; width: 500px; height: 300px; line-height: 50px; text-align: center; background:rgba(255,255,255,0.3); } <div class="demo2-bg"> div class="demo2">晓宇个人博客<br/>背景图半透明,文字不透明<br/>方法:定位+ background:rgba(255,255,255,0.3)</div> </div>
关键字词:html,css