Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Auto-Sizing DIVs (See related posts)

To have a <DIV> shrink and enlarge based on its content, use this CSS:

div.autosize { display: table; width: 1px; }
div.autosize > div { display: table-cell; }


In your HTML, enclose the <DIV> you want autosized in another <DIV> with class="autosize"

Before:

<div>
I want this to be auto sized!
</div>


After:

<div class="autosize">
<div>
I want this to be auto sized!
</div>
</div>


Tested in Firefox, Mozilla, Safari, Opera 7, and Internet Explorer 6.

You need to create an account or log in to post comments to this site.


Click here to browse all 5059 code snippets

Related Posts