/ Published in: CSS
The top left corner of the div will be positioned 50% from the top. Since we want the center of the div to be positioned 50% from the top you need to set a negative top margin equal to half the height of the div. This same trick works for horizontal centering as well. Change top to left and margin-top to margin-left and set the negative margin to be half of the width of the element.
Expand |
Embed | Plain Text
The HTML: 1 </pre> 2 <div id="content">your content here</div> 3 <pre> The CSS: 1 div#content { 2 position: absolute; 3 top: 50%; 4 height: 500px; 5 margin-top: -250px 6 }
You need to login to post a comment.
