I have a div whose width and height are some fixed percentages of the browser-window, say 70% and 80%, with certain min-width
and min-height
. I want this div to be displayed both vertically as well as horizontally centered in the browser window. As the browser window is resized, I want the div to automatically resize and also keep itself in the center.
Firstly, it is not a div of fixed width or height, so I cannot use absolute
positioning with negative margins. I have used the usual position: static
and set left and right margins to auto
for the horizontal centering. This ensures automatic resizing and centering with browser window resize only in the horizontal direction. This kind of thing doesn't work for vertical centering. And I can't use negative margins for that as the position is not absolute
(I need it to be static
for the horizontal).
I saw here and here on StackOverflow that there could be a solution for variable-size divs by using display:table-cell
. Is there preferably any other solution, maybe slightly simpler, using only some setting of position
, margin
etc.?
Here's the demo site where I want to apply this layout.
Thanks a lot in advance!