tags:

views:

25

answers:

1

Hi. I'm trying to achieve a right-hand-floated box, with a variable list of tables or divs (generated via ASP.NET Repeater, but that's not important) to the left. The tables/divs should expand to fill the remaining width.

That would be fine: float the box to the right, and set a margin-right on each of the tables or divs. However, I want the tables/divs to expand to fill the full width of the page after they have 'gone past' the end of the float - basically, to wrap around the floated box, filling the remaining width.

(Here's some code that would be a basis for experimentation: I want the divs - or equivalent tables - to not overlap the floated box, but take the full width available.)

<div style="border: 1px solid black; background-color: red; float:right; width:40em; margin:10px; padding:10px;">
    Hello, world
</div>

<div style="background:yellow; margin:10px; padding:10px;">
    One
</div>

<div style="background:yellow; margin:10px; padding:10px;">
    Two
</div>

<div style="background:yellow; margin:10px; padding:10px;">
    Three
</div>


</body>
</html>

The only thing I have found that gets anywhere close is to have one of the columns within the tables to have a huge width, longer than is possible - e.g. 3000px. The table then 'expands' to try to get to 3000px but can't, and so it fills the available width, taking into account the floated box when it's near the top of the page, and just taking the whole width a little further down when the floated box isn't there anymore.

I hope I have explained this well enough, please comment if not. I did search for duplicates expecting plenty but I believe I didn't find this exact question; only people asking for the same thing but without the tables expanding to full width after the floated box is 'out of the way'. Thanks.

+1  A: 

I have a solution for div's, but not for tables. JsFiddle solution

The div's have "overflow:hidden" so that they fill as much space they can find, but stop if they get to an floated element.

I can't think of a solution for a table. They have a total different flow and I don't believe you can make certain rows smaller then others, but tables are not my specialty...

Justus Romijn
That works great - none of the CSS books I'd been reading for this mentioned that `overflow:hidden` would do that - thanks! (Works with tables by putting the tables within those divs and setting width to 100%)
Kieren Johnstone
(The problem wasn't different rows being different widths, there were lots of repeated tables, each having to behave the same as the divs do in your example)
Kieren Johnstone
Ah then you should be fine here :)! Great to help.
Justus Romijn
Is it just a piece of knowledge you had floating around that said overflow:hidden would fill as much space as possible? I can't think of an alternative that would indicate that wouldn't happen anyway? (Just curious)
Kieren Johnstone
Justus Romijn