CSS: CENTERING THINGS

Centering lines of text

P { text-align: center }
H2 { text-align: center }

Centering a block of text or an image

P.blocktext {
    margin-left: auto;
    margin-right: auto;
    width: 6em
}
...
<P class="blocktext">This rather...
IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto }
...
<IMG class="displayed" src="..." alt="...">

Centering a block or an image vertically

DIV.container {
    min-height: 10em;
    display: table-cell;
    vertical-align: middle }
...
<DIV class="container">
  <P>This small paragraph...
</DIV>

Ref: http://www.w3.org/Style/Examples/007/center

Leave a Reply

Your email address will not be published. Required fields are marked *