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.
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.
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
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.