Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
debt
· 12y ago · 0 comments
center a div both vertically and horizontally to the viewport; also it should stay center when resized.
Comments
[–]
thoughtpalette
12y ago
Absolute Horizontal And Vertical Centering In CSS
http://coding.smashingmagazine.com/2013/08/09/absolute-horiz...
[–]
debt
OP
12y ago
Truth. The div would need a variable height though which would change the design.
[–]
proexploit
12y ago
The page linked includes techniques for both variable height content (e.g. translate -50%) and fixed content.
[–]
ptx
12y ago
Although this used to be a problem with CSS, it has been fixed in modern browsers:
http://philipwalton.github.io/solved-by-flexbox/demos/vertic...
[–]
pjmlp
12y ago
Now make it work across all browsers and operating systems required by your customer.
[–]
elclanrs
12y ago
You can use viewport units in modern browsers. See here
http://caniuse.com/viewport-units