HTML/CSS: Creating a centered div with a min-width

Posted by Alessandro Vernet on Stack Overflow See other posts from Stack Overflow or by Alessandro Vernet
Published on 2009-02-02T04:33:34Z Indexed on 2010/06/09 21:02 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

I'd like to have on my page a div which is centered and has a certain width, but which extends beyond that width if required by the content. I am doing this with the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <style type="text/css">
            .container-center {
                text-align: center;
            }
            .container-minwidth {
                min-width: 5em;
                display: inline-block;
                border: 1px solid blue;
            }
        </style>
    </head>
    <body>
        <div class="container-center">
            <div class="container-minwidth">
                a
            </div>
        </div>
    </body>
</html>

This works great on Firefox/Safari, but not on IE6, which doesn't understand the display: inline-block. Any advice on how to make this work on IE6 as well?

© Stack Overflow or respective owner

Related posts about html

Related posts about css