html - 绝对位置div不填充容器div css

标签 html css

我在容器 div 中有一个 绝对定位 div。绝对定位的 div 的背景色没有填充容器 div。容器 div 的高度根据内容是动态的。如何使定位的 div 的背景颜色填充它的容器 div?

HTML:

<div class="container">
test<br />
test<br />
test<br />

<div class="showbg">
test
</div>

</div>

CSS:

.container{ background-color:#CCCCCC;  width:300px;}
.showbg{ background-color:#FFFFFF; position:absolute; width:300px; margin-top:-65px; opacity:0.4;
filter:alpha(opacity=40);}

最佳答案

.container {position: relative;}
.showbg {position:absolute; top:0;bottom:0;left:0;right:0;}

关于html - 绝对位置div不填充容器div css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20298783/

相关文章:

html - 每个 CSS3 框架重载比较?

javascript - Foundation 中的默认字体大小?

html - 缩放页面时对齐问题

javascript - 如何简要介绍我的 jquery 代码?

html - css 使悬停在 li 时显示图像

javascript - Bootstrap 3 Glyphicons 显示不正确

css - 使用字体 : inherit? 的目的是什么

css - 在 Wordpress 的 get_search_form() 上更改输入值

javascript - 文件读取器内存泄漏

python - Beautiful Soup - 下载 css 元素