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.
You can do it simply by using
display: inline;
(orwhite-space: nowrap;
).I hope you find this useful.
display: inline-block
adds an extra margin to your element.I would recommend this:
Bonus: You can also now easily center that fancy new
#element
just by addingmargin: 0 auto
.OK, in many cases you even don't need to do anything as by default div has
height
andwidth
as auto, but if it's not your case, applyinginline-block
display gonna work for you... look at the code I create for you and it's do what you looking for:If you have containers breaking lines, after hours looking for a good CSS solution and finding none, I now use jQuery instead:
What works for me is:
in the
div
. (Tested on Firefox and Google Chrome).