Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
css透明度怎么设置?三种css图片透明度的设置方法_创想鸟

css透明度怎么设置?三种css图片透明度的设置方法

css透明度的设置在网页的设计中是经常需要用到的,有时为了设计出的网页更加的美观,会对图片进行透明化处理,这样网页上面的内容就不会看不见,有的网页因为图片作为背景,也会更加美观,那么,css中的透明度怎么设置呢?今天这篇文章就来给大家分享css中图片透明度的设置方法

css中与设置透明效果相关的属性有两个:opacity和rgba。(推荐视频课程:css教程)

下面我们就用这两个属性来分别设置图片透明度的效果。

首先我们来看css中opacity属性设置图片透明度的例子

css:

立即学习“前端免费学习笔记(深入)”;

.opacity1, .opacity2, .opacity_img { display: inline-block; }.opacity1 { filter: Alpha(opacity=0); }.opacity2 { filter: Alpha(opacity=50); }.opacity_img { filter: Alpha(opacity=100); }:root .opacity1 { opacity: 0; filter: none; }:root .opacity2 { opacity: .5; filter: none; }:root .opacity_img { opacity: 1; filter: none; }

html:

效果如下:

css透明度怎么设置?三种css图片透明度的设置方法

注意:目前主流的浏览器都支持opacity:value写法,value取值为0-1,0为完全透明,1为完全不透明。但是在IE8及之前的版本中是不支持这种写法,那么我们可以通过滤镜来解决 filter:alpha(opacity=value),value取值为0-100,0为完全透明,100为完全不透明。就像上面例子那样。

我们再来看看css中rgba设置图片透明的例子:

html:

背景图半透明,文字不透明
方法:定位+ background:rgba(255,255,255,0.3)

css:

立即学习“前端免费学习笔记(深入)”;

.demo2-bg{    background: url(//image.zhangxinxu.com/image/study/s/s256/mm1.jpg) 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);

效果如下:

css透明度怎么设置?三种css图片透明度的设置方法

说明:此方法浏览器兼容性好,图片和内容都能很好分离实现背景图片半透明效果,而文字、边框等样式与内容不受影响。只是多了一层div,使用绝对定位样式来实现重叠层叠。

设置背景颜色值与透明度。前3个255为代表RGB黑色,0.3代表透明度为30%。

最后,我们再来看一个图片毛玻璃效果的设置方法:

背景图半透明,文字不透明
方法:背景图+ filter:blur
.demo1{    width: 500px;    height: 300px;    line-height: 50px;    text-align: center;}.demo1:before{    background: url(//image.zhangxinxu.com/image/study/s/s256/mm1.jpg) 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);}

效果如下:

2345截图20180906151537.png

本篇文章到这里就结束了,更多的关于css图片的处理方法可以参考css手册。

相关推荐:

CSS鼠标点击式变化图片透明度_html/css_WEB-ITnose

图片+css实现半透明引导页_html/css_WEB-ITnose

2345截图20180906153257.png2345截图20180906153515.png

以上就是css透明度怎么设置?三种css图片透明度的设置方法的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1611480.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
CSS隐藏的方式有哪些?display:none,opacity:0,visibility: hidden有什么不同
上一篇 2025年12月24日 02:20:32
CSS3 什么是弹性盒子?display属性中flex与box属性值的区别和用法
下一篇 2025年12月24日 02:20:50

相关推荐

发表回复

登录后才能评论
关注微信