The fast way to center a block element

1 Jan

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 yet

Leave a Reply