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.
There are two better solutions
display: inline-block;
OR
display: table;
Out of these two
display:table;
is better.For
display:inline-block;
you can use the negative margin method to fix the extra spaceTry
display: inline-block;
. For it to be cross browser compatible please use the below css code.Not knowing in what context this will appear, but I believe the CSS-style property
float
eitherleft
orright
will have this effect. On the other hand, it'll have other side effects as well, such as allowing text to float around it.Please correct me if I'm wrong though, I'm not 100% sure, and currently can't test it myself.
Just put a style into your CSS file
This will make parent div width same as the largest element width.
Revised (works if you have multiple children): You can use jQuery (Look at the JSFiddle link)
Do not forget to include the jQuery...
See the JSfiddle here