【发布时间】:2015-08-09 12:29:33
【问题描述】:
我不想为任何元素设置任何固定高度,这可能吗?
<div class="floated">
<div class="Content">
<p>text</p>
</div>
</div>
【问题讨论】:
-
需要HTML/CSS相关代码。
标签: css
我不想为任何元素设置任何固定高度,这可能吗?
<div class="floated">
<div class="Content">
<p>text</p>
</div>
</div>
【问题讨论】:
标签: css
body {
height : 1000px; /* needed to let the height percentage "MyDiv" correctly work */
}
#myDiv {
position : relative;
height : 20%;
display : table;
border : solid 1px black; /* to see the behaviour of the div, can be removed */
}
#myContainer {
display : table-cell;
vertical-align : middle;
}
<body>
<div id="myDiv" >
<div id="myContainer">
my super content !
</div>
</div>
</body>
在第一个 div 容器上使用 display : table,在包含您的文本或图像的子 div 中使用 display : table-cell ....
【讨论】: