温馨提示×

温馨提示×

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

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

CSS如何实现层透明

发布时间:2022-03-05 10:12:15 来源:亿速云 阅读:134 作者:小新 栏目:web开发

这篇文章给大家分享的是有关CSS如何实现层透明的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体分析如下:

这个代码段是演示用CSS控制一个DIV层的透明效果,大家可以看到平铺的背景已经显现出来,实际上比较简单就可以实现,就是用CSS控制一个DIV层,定义样式表时加入filter:alpha(opacity=65);这句代码,里面的值是用来控制透明度的,你可以试着改变它的值,会有不同的透明效果。

代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS定义层的透明效果</title>
<style type="text/css">
body { 
font-family: Arial, Helvetica, sans-serif; 
line-height: 1.5;
background: url(http://files.jb51.net/file_images/article/201505/2015513164008952.jpg);
color: #fff;
width: 770px;
margin: 0 auto;
padding: 50px;
}
h2,h3 { 
color: #77AFC7 !important;
margin-bottom: 0;
line-height: 1.2em;
}
p {
margin-top: 0;
}
a {
color: #aaa;
}
a:hover {
color: #FFF !important;
text-decoration: none;
}
code { 
background-color: #100;
padding: 0.2em 0.5em;
display: inline-block;
}
#wrapper { 
overflow: hidden;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
background: #000;
opacity: 0.65;
-moz-opacity: 0.65;
filter:alpha(opacity=65);
}
.container {
position: relative;
float: left;
}
.content {
position: relative;
float: left;
}
#column-1 {
width: 500px;
}
#column-2 {
width: 250px;
margin-left: 20px;
float: left;
display: inline;
}
#column-1 .content {
padding: 20px;
width: 460px;
}
#column-2 .content {
padding: 10px;
width: 230px;
}
* html #column-1 .overlay { height: expression(document.getElementById("column-1").offsetHeight); }
* html #column-2 .overlay { height: expression(document.getElementById("column-2").offsetHeight); }
</style>
</head>
<body>
<div id="wrapper">
<div id="column-1" class="container">
<div class="overlay"></div>
<div class="content">
<h3>透明的网页.</h3>
<p>IE6,FF测试通过</p>
<p>这是一个透明的网页,还不错吧?实际上是用CSS控制DIV层的半透明状态,这样会使平铺的背景显现出来,看上去酷了不少。</p>
<p>By <a href="/">CC-Public Domain</a></p>
</div>
</div>
<div id="column-2" class="container">
<div class="overlay"></div>
<div class="content">
<h3>A sidebar</h3>
<p>这是右侧,你可以尝试修改一下。</p>
</div>
</div>
</div>
</body>
</html>

感谢各位的阅读!关于“CSS如何实现层透明”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

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

css
AI