I have a layout similar to:
I would like for the div
to only exp
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div id="content_lalala">
this content inside the div being inside a table, needs no inline properties and the table is the one expanding to the content of this div =)
</div>
</td>
</tr>
</table>
I 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. =)
Tampering around with Firebug I found the property value -moz-fit-content
which exactly does what the OP wanted and could be used as follow:
width: -moz-fit-content;
Although it only works on Firefox, I couldn't find any equivalent for other browsers such as Chrome.
OK, in many cases you even don't need to do anything as by default div has height
and width
as auto, but if it's not your case, applying inline-block
display gonna work for you... look at the code I create for you and it's do what you looking for:
div {
display: inline-block;
}
<div>
<table>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ultrices feugiat massa sed laoreet. Maecenas et magna egestas, facilisis purus quis, vestibulum nibh.</td>
<td>Nunc auctor aliquam est ac viverra. Sed enim nisi, feugiat sed accumsan eu, convallis eget felis. Pellentesque consequat eu leo nec pharetra. Aenean interdum enim dapibus diam.</td>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ultrices feugiat massa sed laoreet. Maecenas et magna egestas, facilisis purus quis, vestibulum nibh.</td>
</tr>
</table>
</div>
<div class="parentDiv" style="display:inline-block">
// HTML elements
</div>
This will make parent div width same as the largest element width.
You can try fit-content (CSS3):
div {
width: fit-content;
/* To adjust the height as well */
height: fit-content;
}
Try display: inline-block;
. For it to be cross browser compatible please use the below css code.
div {
display: inline-block;
display:-moz-inline-stack;
zoom:1;
*display:inline;
border-style: solid;
border-color: #0000ff;
}
<div>
<table>
<tr>
<td>Column1</td>
<td>Column2</td>
<td>Column3</td>
</tr>
</table>
</div>