CSS图像透明度怎么设置

发布时间:2022-03-16 15:53:10 作者:iii
来源:亿速云 阅读:143

这篇文章主要介绍了CSS图像透明度怎么设置的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇CSS图像透明度怎么设置文章都会有所收获,下面我们一起来看看吧。

定义和用法

opacity 属性设置元素的不透明级别。

CSS图像透明度怎么设置

语法

opacity: value|inherit;

CSS图像透明度怎么设置

实例一:创建透明图像

CSS图像透明度怎么设置

<!DOCTYPE html>
<html>
<head>
<style>
img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
img:hover
{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
</style>
</head>
<body>
<h2>图像透明度</h2>
<img src="http://pic.58pic.com/58pic/15/36/00/73b58PICgvY_1024.jpg" alt="Peach Blossom" />
<p><b>注释:</b>在 IE 中,必须添加 <!DOCTYPE>,这样才能将 :hover 选择器用于除了 <a> 之外的其它元素。</p>
</body>
</html>

实例二:半透明框中加文本

呈现方式

CSS图像透明度怎么设置

<!DOCTYPE html>
<html>
<head>
<style>
.background
{
  width: 400px;
  height: 266px;
  background: url(http://pic.58pic.com/58pic/15/36/00/73b58PICgvY_1024.jpg) no-repeat ;
  border: 1px solid black;
}
.transbox
{
  width: 338px;
  height: 204px;
  margin:30px;
  background-color: #ffffff;
  border: 1px solid black;
  /* for IE */
  filter:alpha(opacity=60);
  /* CSS3 standard */
  opacity:0.6;
}
.transbox p
{
  margin: 30px 40px;
}
</style>
</head>
<body>
<div class="background">
<div class="transbox">
<p>
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.</p>
</div>
</div>
</body>
</html>

关于“CSS图像透明度怎么设置”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“CSS图像透明度怎么设置”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. css设置透明度的方法
  2. CSS怎么设置透明度

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css

上一篇:CSS背景图片如何固定

下一篇:CSS title标题前怎么加小图标

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》