19. Example (continued): Centering, for IE

19. Example (continued): Centering, for IE

Unforntunately, IE does not support display: table, and IE versions 6 and earlier do not support margin: auto.

To get the shrink-wrap effect in IE, we must violate our clean design principles and make an actual one-celled table in HTML.

<table style="
margin: auto; border: 1px solid red;">
<tr> <td>...

Now, to center the box in IE 6, we take advantage of yet another IE bug: IE incorrectly applies text-align: center to contained boxes, not just contained text. So we put our shrink-wrapped box inside another box with text-align: center, but then we must add text-align: left to the table so the text is not centered within the table. We also keep the margin: auto for standard-compliant browsers.

<div style='text-align: center;'>
<table style="
text-align: left; margin: auto; border: 1px solid red;">
<tr> <td>...
Ken Keys, CAIDA, 2006-12-01