【发布时间】:2013-02-22 22:21:30
【问题描述】:
这是http://jsfiddle.net/FW38N/1/的例子
我怎样才能使 div(容器)具有高度:自动,而不是使其具有固定高度
.container{
width:auto;
height:auto;
background-color:black;
position:relative;
}
.text {
position:absolute;
width:50px;
height:50px;
background-color:red;
}
<div class='container'>
<div class='text'>
</div></div>
【问题讨论】:
-
我认为这不适用于 css,因为“文本”是绝对的,就像在“其他维度”中一样,而“容器”不知道它的维度。也许包括一些 JavaScript 来获取“文本”大小,并将该大小(高度)应用于“容器”。
标签: html css styles stylesheet