Entry
How do I center a block element like a DIV in NN6?
May 26th, 2000 08:58
Martin Honnen,
CSS 2 which NN6 implements allows that by
- setting a width on the DIV
- setting margin-left and margin-right to auto
That way the left and right margin of the DIV will be equal meaning the
block level element becomes centered.
Example
<HTML>
<HEAD>
</HEAD>
<BODY>
<DIV STYLE="width: 50%; margin-left: auto; margin-right: auto;
background-color: orange; color: white;"
>
JavaScript.FAQTs.com
</DIV>
<DIV STYLE="width: 200px; background-color: orange; color: white;"
ONCLICK="this.style.marginLeft = this.style.marginRight = 'auto';"
>
Click to center this div.
</DIV>
</BODY>
</HTML>