如何将浮动div垂直对齐到底部?
因为示例规则: http://jsfiddle.net/rudiedirkx/wgue7/
我如何获得酒吧到底部而不是顶部?现在它们粘在容器的顶部(#bars
),但我希望它们粘在底部。
正如你所看到的,我不知道最高条的高度,所以我也不知道容器的高度。
这些 q+a 没有帮助:垂直对齐浮动 div、垂直对齐浮动 DIV
应该很简单吧?如果有帮助:它只需要在合适的浏览器中工作。
附言。条形的数量是可变的(示例中没有)并且它们的高度也是可变的。只有它们的宽度是静态的。绝对定位不会有帮助,因为容器 div 没有测量值。
Because examples rule: http://jsfiddle.net/rudiedirkx/wgue7/
How do I get the bars to the bottom instead of the top? Now they're sticking to the top of the container (#bars
) but I want them sticking to the bottom.
As you can see, I don't know the height of the highest bar, so I don't know the height of the container.
These q+a don't help: Vertically align floating divs, Vertically align floating DIVs
Should be simple, right? If it helps: it only has to work in decent browsers.
PS. Number of bars is variable (not in the example) and their heights are. Only their widths are static. Positioning absolute
won't help, because the container div doesn't have measurements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就能解决问题:
它使用父 div 上的
display: table-cell;
,默认情况下应用vertical-align: benchmark;
。这改变了子 div 上对float: left;
的需求,并允许我们使用display: inline-block;
。这也消除了 CSS 清除修复的需要。编辑 - 根据 @thirtydot 的评论,向子 div 添加
vertical-align:bottom;
可消除底部的间隙。因此,我改变了上面的CSS和jsFiddle。我保留了
display: table-cell;
,这样父 div 用 0 填充包裹子 div,看起来又漂亮又时髦!This will do the trick:
It uses
display: table-cell;
on the parent div, which by default hasvertical-align: baseline;
applied. This changes the need forfloat: left;
on the child divs and allows us to usedisplay: inline-block;
. This also removes the need for your CSS clear fix.EDIT - Per @thirtydot's comments, adding
vertical-align: bottom;
to the child divs removes the gap at the bottom.Therefore, I changed CSS above and jsFiddle. I kept the
display: table-cell;
so that the parent div wraps the child divs with 0 padding and looks nice and snazzy!灵活盒!弹性盒是最好的。
示例: http://jsfiddle.net/rudiedirkx/7FGKN/
Flexbox 使这变得非常简单(并且不要忘记正确):
就是这样两行CSS:
display: flex
和align-items: flex-end
。FLEXBOX! Flexbox is the best.
Example: http://jsfiddle.net/rudiedirkx/7FGKN/
Flexbox makes this ridiculously simple (and not to forget correct):
That's it Two lines of CSS:
display: flex
andalign-items: flex-end
.