【发布时间】:2013-06-12 09:41:14
【问题描述】:
我有一个div,里面有另一个div。第二个div 有width、height 和background-color: green。这个有绝对位置,所以它的容器没有显示出来。
<div id="root">
<div id="r1">
<div id="r2">
</div>
</div>
Mas
</div>
CSS 文件
#root{
width:300px;
background-color: red;
}
#r1{
position: relative;
width: 100px;
background: yellow;
}
#r2{
position: absolute;
display: inline-block;
width: 50px;
height: 50px;
left: 0;
background-color: green;
}
我想知道是否有可能显示它的容器并用绝对位置包裹div。
我想看到这样的东西,但不使用相对位置,也不给容器增加高度。
谢谢!
【问题讨论】:
-
请在您的问题中也包含相关代码。
-
当你声明一个 div 为绝对的,那么它就不会包含在父标签中。所以无法根据需要进行包装。
-
`不使用相对位置且不添加高度`?有什么原因吗?
-
@zey 是的,我想在 CSS 中找到与 Android 布局中的“WRAP_CONTENT”属性类似的方法...谢谢大家!