Hacker News new | past | comments | ask | show | jobs | submit login

A few additions. If you know the width and height of the element, centering horizontally & vertically can be achieved with one <div> like so:

.center-div { height:100px; width: 100px; position:absolute; top:50%; left:50%; margin: -50px 0 0 -50px; }

This can be modified for the 'centering at the bottom of the page' example, but with more efficient code.

More challenging is centering the unknown: http://css-tricks.com/centering-in-the-unknown/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: