tags:

views:

60

answers:

4

I just need a sanity check here... DEMO

Basically, I can't figure out how to get the box under the link to get wider as more content is added. It seems fixed to the width of the parent div (or the width of, say, the longest element like the select or a really long word with no spaces), despite being absolutely positioned. I use this trick all the time with ul and li but it doesn't make sense to use that in my situation, and for some crazy reason it just won't work with a div inside a div.

I don't want to set a width (which, of course, works) because I don't always know what will be in this box. GRR

Thanks :\

EDIT

It appears that removing the position:relative from the parent element does, in fact, allow the box to get wider. However, relative positioning is necessary because I need the child div to be absolutely positioned under the parent div, and the parent div's location is technically dynamic (so no figuring out absolute page coords).

A: 

Have you try the pre tag

<pre>text goes here</pre>

this will cause to break the line only wherever you insert a <br />

Garis Suero
thanks, but this doesn't work :\
Jason
A: 

div#parent has position: relative;. Try removing that declaration. In my environment, that causes the div to expand as needed.

echo
the reason the position: relative is there is because the div is absolutely positioned... the actual action is for the child div to be off the page and the left position changed when the parent is hovered
Jason
although, you are correct in that removing the `position:relative` will make it work :\
Jason
A: 

I am in Google Chrome 6.0.422.0 dev and as I add content (text) the grey box expands horizontally and vertically as necessary. What browser are you using?

omizzle
i was using what i thought was the latest version of chrome! ha... 5.0.375.70 but also checking in FF 3.6.3
Jason
Here are a few screenshots (Im on Mac OS X 10.6.3):Firefox 3.6.4 - http://i45.tinypic.com/6ih05w.png | Chrome - 6.0.422.0 dev - http://i46.tinypic.com/2q15kzp.png | Safari 4.0.5 - http://i46.tinypic.com/1904fq.png
omizzle
ha ok yeah, that's not the desired functionality i'm looking for. i was looking for the box expanding horizontally regardless of spaces in the content. the accepted answer did the trick :) thanks for looking into it anyways!
Jason
+2  A: 

If I understand correctly...

Floating containers (i.e., #parent) will fit to their contents with the default of width: auto. The contents will line-break where possible to prevent the width from ever increasing.

To counter this, you should just need to employ white-space: nowrap.

Either for the contents as a whole:

.advanced {
    /* ... */
    white-space: nowrap;
}

Or, define a new class to allow for more flexible usage:

.line {
    white-space: nowrap;
}

Then, (e.g.) wrap each label/select as:

<div class="line">
    <label>Show:</label>
    <select name="showAll">
        <option value="true">My Team</option>
        <option value="false">Mine Only</option>
    </select>
</div>
Jonathan Lonowski
`white-space: nowrap` FTW! Thanks a lot man. I don't know why I didn't think of that before... durrrr
Jason