Monday, 7 September 2015

How to center a div, The fast way to center a block element

How to center a div, The fast way to center a block element

There are several ways of centering a div (or 'layer' in Dreamweaver speak). I'm going to show the one I think is easiest to implement because all it takes is a snippet of standards compliant code, and a doc type change.

Example

This div/layer should be horizontally centered

CSS:

div#centerdiv {
width: 200px;
border: 1px solid red;
margin-left: auto;
margin-right: auto;
}

HTML:

<div id="centerdiv">This div/layer should be horizontally centered</div>

No comments:

Post a Comment