下面我有 3 行 (.child
) 具有不同的高度。
父级(#parent
)的高度无法预先知道,如果其父级(#parent
的父级)的高度发生变化,它实际上会发生变化.
我可以使用一些 CSS 组合来设置这些行之间的边距,使行在垂直方向上均匀分布吗?
类似于当我们有不同宽度的单元格时,我们希望在水平方向上均匀分布。这很容易通过使用 display: table-cell;
我相信,即使他们的 parent 的宽度是未知的。
JSFIDDLE:http://jsfiddle.net/7ty82k3b/5/
CSS:
#parent {
display: table;
position: fixed;
top: 0px;
left: 0px;
height: 100%;
width: 93px;
background-color : red;
}
.child {
position : relative;
float: left;
clear: both;
border: 1px solid blue;
display: table-row;
width: 91px;
}
span.child {text-align:center;}
HTML:
<body>
<div id="parent">
<img class="child" src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
<span class="child">Hey!</span>
<img class="child" src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
</div>
</body>
最佳答案
将您的 .child
包裹在一些 .row
中,这样您就可以将 .row
显示为 table-row
和 .child
作为 table-cell
然后 vertical-align: middle
它们。另外,请记住图像是哭泣的婴儿,不能很好地处理“异国情调”的显示,所以不要尝试将它们显示为 table-row
或 table-cell
.
#parent {
display: table;
position: fixed;
top: 0px;
left: 0px;
height: 100%;
width: 93px;
background-color: red;
}
.row {
display: table-row;
}
.child {
position: relative;
border: 1px solid blue;
display: table-cell;
vertical-align: middle;
}
span.child {
text-align: center;
}
<div id="parent">
<div class="row">
<div class="child">
<img src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
</div>
</div>
<div class="row"> <span class="child">Hey!</span>
</div>
<div class="row">
<div class="child">
<img src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
</div>
</div>
</div>
关于html - 当父级高度为 100% 时,如何均匀分布不同高度的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26290190/