« Please mail me the Internet | Main | Girls = Boys at Math »

Resizing div with font size

I was working on a complicated layout where I was trying to center a div. For some reason, the usual auto margins technique would not work because the div always expanded to the full width of its container even though the width was not set to 100%.

The only way I could get the div to center was to use auto left and right margins in conjunction with setting a width. However, I wanted the layout to scale gracefully if the font size was changed. The solution was to specify the width in em. This makes the div resize with the font. Quick and dirty, but it works well enough until I have time to come back to take a closer look at the problem again.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)