I have a layout similar to:
<div>
<table>
</table>
</div>
I would like for the div
to only expand to as wide as my table
becomes.
I have a layout similar to:
<div>
<table>
</table>
</div>
I would like for the div
to only expand to as wide as my table
becomes.
A CSS2 compatible solution is to use:
You can also float your div which will force it as small as possible, but you'll need to use a clearfix if anything inside your div is floating:
I tried
div.classname{display:table-cell;}
and it worked!The answer for your question lays in the future my friend ...
namely "intrinsic" is coming with the latest CSS3 update
unfortunately IE is behind with it so it doesn't support it yet
More about it: CSS Intrinsic & Extrinsic Sizing Module Level 3 and Can I Use?: Intrinsic & Extrinsic Sizing.
For now you have to be satisfied with
<span>
or<div>
set toI know people don't like tables sometimes, but I gotta tell you, I tried the css inline hacks, and they kinda worked in some divs but in others didn't, so, it was really just easier to enclose the expanding div in a table...and...it can have or not the inline property and still the table is the one that's gonna hold the total width of the content. =)
We can use any of the two ways on the
div
element:or,
I prefer to use
display: table;
, because it handles, all extra spaces on its own. Whiledisplay: inline-block
needs some extra space fixing.You can try
fit-content
(CSS3):