3 ms·
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 {
by addedlovely 13y ago
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/ http://css-tricks.com/centering-in-the-unknown/