Clive Walkden

PHP, MySQL, HTML5, CSS3, jQuery code and ideas.

CSS Posts

CSS center content within a div

CSS center content within a div

in CSS3
by
with 0 Comments

 

Here’s an old bit of code that I found to position something centrally inside an element.
 
[code lang="css"]
#idOfTheDiv {
   width: 400px; /* here you put the width that you need */
   height: 200px; /* here you put the height that you need */
   position:absolute;
   left:50%;
   top:50%;
   margin-left:-200px; /* this number always to be the width divided two in negative */
   margin-top:-100px; /* this number always to be the height divided two in negative */
}
[/code]
comments powered by Disqus