I'm doing some work with CSS, and I have an <li> element with a <div> element inside of it. The <div> element assumes the width of the enclosing <li> element, but the text content inside the <div> is wider than the <li> (and therefore goes onto two lines). What I want to do is make the <div> the same width as its longest text element, does anyone know how I can do this? Thanks.
<ul style="display: inline-block; list-item-style: none">
<li id="foo" style="float: left; list-style-type: none; position: relative;">
<a href="...">brief text</a>
<div id="bar" style="position: absolute; width=???">
<ul>
<li>a long chunk of text</li>
<li>an even longer piece of text</li>
</ul>
</div>
</li>
</ul>
Right now, the width of div#bar is equal to 100% of the width of its enclosing element, li#foo, and the width of li#foo is equal to the width of the text in its <a> tag (plus padding and borders). What I want to do is make div#bar be the width of <li>an even longer piece of text</li>, but I can't figure out how to accomplish that, even with Javascript.... or am I going to be forced to use an absolute measurement for the width? Any advice would be greatly appreciated.