通常会<div>
展开以填充内容insize。
<div>
<p>Hello</p>
</div>
<div>
缩放以包含<p>
是否可以让<div>
在绝对定位时执行此操作?
在我的情况下,我有一个设置高度和宽度的模态,但我想让它缩放到内容。
答案 0 :(得分:0)
这样的东西? http://jsfiddle.net/3L99pycm/
CSS:
div {
position: absolute;
left: 50%;
top: 100px;
background-color: red;
width: 30%;
height: 100px;
}
p {
background-color: blue;
color: white;
}
答案 1 :(得分:0)
div的行为与其位置无关,很可能问题是你在某处设置了固定大小的参数。
答案 2 :(得分:0)
嗯,你不需要做任何特别的事情来为孩子做出绝对的div。我在这里添加了一个例子http://jsfiddle.net/rtkvswmn/
CSS
div {
position: absolute;
background: red;
}
p{
width: 100px;
background: blue;
text-align: center;
}