/ Published in: CSS
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* CSS Document */ .centered_div { width: 100px; height: 100px; position: absolute; top: 50%; left: 50%; margin-left: -50px; margin-top: -50px; background: red; } Here is another example with size 500 x 200 px. /* CSS Document */ .centered_div { width:500px; height: 200px; position: absolute; top: 50%; left: 50%; margin-left: -250px; margin-top: -100px; background: red; }
URL: http://www.dezinerfolio.com/2007/05/02/the-simplest-way-to-horizontally-and-vertically-center-a-div