当div的高度不固定时,没有Javascript的div垂直居中
I would like to vertical center a div
without JavaScript when its height isn't fixed.
I found here one idea.
I wonder if there are other solutions to this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有效:
这是链接:http://jsbin.com/uvodop/2/edit
看看如何它在盒子内垂直对齐。高度也不固定。
希望它能回答您的问题。
This works:
Here's link: http://jsbin.com/uvodop/2/edit
See how it's vertically aligned within the box. Height as well isn't fixed.
Hope it answers your question.
虽然这是一个旧线程,但我认为这个答案可能会对某人有所帮助。如果IE的版本灵活到至少IE>; 8、然后您可以使用
display:table-cell
并使用默认的vertical-align
功能。在下面的代码中,将在中间垂直对齐的 div 未分配任何高度,但为父级分配 100% 高度以填充屏幕。
看看这个
Though this is an old thread, I think this answer might help someone. If the version of IE is flexible to at least IE > 8, then you can use
display:table-cell
and use the defaultvertical-align
feature.In the code below, the
div.hover
which is the div that is going to be vertically aligned middle is not assigned any height however the parent(s) are assigned 100% height to fill the screen.Check this out