博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSS 图像透明度
阅读量:2383 次
发布时间:2019-05-10

本文共 1506 字,大约阅读时间需要 5 分钟。

CSS 图像透明度

通过 CSS 创建透明图像是很容易的。

注释:CSS opacity 属性是 W3C CSS 推荐标准的一部分。

实例 1 - 创建透明图像

定义透明效果的 CSS3 属性是 opacity

首先,我们将展示如何通过 CSS 来创建透明图像。

常规图像:

http://img.mukewang.com/5698d8f10001365a02160146.jpg

带有透明度的相同图像:

http://img.mukewang.com/5698d8fd0001b21e02140144.jpg

请看下面的 CSS:

img{opacity:0.4;filter:alpha(opacity=40); /* 针对 IE8 以及更早的版本 */}

IE9, Firefox, Chrome, Opera 和 Safari 使用属性 opacity 来设定透明度。opacity 属性能够设置的值从 0.0 到 1.0。值越小,越透明。

IE8 以及更早的版本使用滤镜 filter:alpha(opacity=x)。x 能够取的值从 0 到 100。值越小,越透明。

实例 2 - 图像透明度 - Hover 效果

请把鼠标指针移动到图像上:

http://img.mukewang.com/5698d909000140ee02130141.jpg

CSS 是这样的:

img{opacity:0.4;filter:alpha(opacity=40); /* 针对 IE8 以及更早的版本 */}img:hover{opacity:1.0;filter:alpha(opacity=100); /* 针对 IE8 以及更早的版本 */}

第一个 CSS 代码块类似实例 1 中的代码。此外,我们已经设置了当鼠标指针位于图像上时的样式。在这个例子中,当指针移动到图像上时,我们希望图像是不透明的。

对应的 CSS 是:opacity=1

IE8 以及更早的浏览器:filter:alpha(opacity=100)

当鼠标指针移出图像后,图像会再次透明。

实例 3 - 透明框中的文本

This is some text that is placed in the transparent box. This is some text that is placed in the transparent box. This is some text that is placed in the transparent box. This is some text that is placed in the transparent box. This is some text that is placed in the transparent box.

源代码是这样的:

This is some text that is placed in the transparent box.This is some text that is placed in the transparent box.This is some text that is placed in the transparent box.This is some text that is placed in the transparent box.This is some text that is placed in the transparent box.

首先,我们创建一个 div 元素 (class="background"),它有固定的高度和宽度、背景图像,以及边框。然后我们在第一个 div 内创建稍小的 div (class="transbox")。"transbox" div 有固定的宽度、背景色和边框 - 并且它是透明的。在透明 div 内部,我们在 p 元素中加入了一些文本。

转载地址:http://ovfab.baihongyu.com/

你可能感兴趣的文章
外部修改应用程序图标的做法
查看>>
database disk image is malformed解决方法
查看>>
有关error PRJ0003错误的思考
查看>>
实现自定义对话框程序快捷键的两种方法
查看>>
如何对抗微软霸权,google给我们上了一课
查看>>
未能将基于用户的Visual C++项目设置保存到user文件错误的解决
查看>>
获取windows版本信息的做法
查看>>
忆父亲
查看>>
png库结合zlib库使用出现的一个链接问题的解决
查看>>
STL数组和com数组相互转换的做法
查看>>
开发平台软件中关于第三方库管理的一些思考
查看>>
svn创建分支的做法
查看>>
“当前不会命中断点。源代码与原始版本不同”的问题的有效解决办法
查看>>
对面向对象和面向过程的一些新理解
查看>>
软件开发中的资源管理
查看>>
有关博客的一些断想
查看>>
Windows Server2008上安装VS2008出错及解决办法
查看>>
打开word2010每次都要配置进度的解决办法
查看>>
略论并行处理系统的日志设计
查看>>
开发人员应具备的产品设计意识
查看>>