图片透明

<style>
body {background:#ccc;}
#box {width:200px;position:relative;}
.content {width:180px;position:relative;z-index:1;}
.bg {width:200px;background:red;filter:alpha(opacity=40);opacity:0.4;position:absolute;top:0;left:0;}
</style>
<script>
window.onload = function(){
    (function(){ document.getElementByIdx("AutoBg").style.height = document.getElementByIdx("Con").offsetHeight + "px"; })();
}// 让ID名为AutoBg的元素的高 等于 ID名为Con的高
</script>

html
<div id="box">
    <div class="content" id="Con">文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少文字的内容可多可少</div>
    <div class="bg" id="AutoBg"></div>
</div>

posted @ 2016-05-15 23:56  小书匠  阅读(169)  评论(0编辑  收藏  举报