Skip to main content
gamedev.net
🔒 Locked

[web] CSS Layout - Fluid Width

Started by jbadams Oct 17, 2005 at 5:52 AM 8 replies 7k views
Original Post
jbadams
jbadams
Hi all, I've been trying for a while to get a particular layout to work correctly, but I havn't been able to find any solutions myself, and have been unable to locate any solutions elsewhere either. Basically, I've got a number of divs being used to position content. For simplicities sake, I'll just talk about two for now. I have them layed out something like the following:

+---------------------------------------------------+
|+------------++-----------------------------------+|
|| FIXED      || NON-FIXED WIDTH DIV               ||
|| WIDTH DIV  ||                                   ||
|+------------++-----------------------------------+|
|           REMAINING SPACE IN BROWSER              |
|                                                   |
+---------------------------------------------------+
Now, as that hopefully shows, I've got a fixed width div floated to the left, it's sitting in the upper-left corner of the browser window. Sitting next to that I have another div, with a non-fixed width. I'm trying to get this non-fixed width div to expand to fill all the remaining space, but have been unable to do so thus far. I don't want to fix the width. Setting the width to a % takes it's value from the container if I'm not mistaken, which results in the (correct but undesired) behavior of it being pushed down below the fixed-width and expanding to fill the browser. So, does anyone know of a solution, or have any ideas where I could look? I'm also going to be a bit of a pain in the a$$ and say I'd like to support as many browsers as possible correctly (at least Opera, Firefox, and IE), and that &#106avascript should be avoided if possible (if there's no other way I'll probably use &#106avascript to calculate an appropriate fixed width instead).
- Jason Astle-Adams
Sander
Sander
That's actually a *lot* trickier than it sounds. Basically you have a two-column layout at the top (left column fixed with) and room below that. I suggest you take a look at http://css-discuss.incutio.com/?page=TwoColumnLayouts over at css-discuss to see a couple of examples on how to accomplish this. http://bluerobot.com/web/layouts/layout1.html looks simple enough.

Edit: http://www.ryanbrill.com/floats.htm looks good too. Just use a short two-column layout at the top, regular page contents below that.
benryves
benryves
Quote:
So, does anyone know of a solution, or have any ideas where I could look?
Purists will hate me for this, but a table-based layout for that part would probably be quite a lot easier to do.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
kanzler
kanzler
Pure CSS is absolutely useless for column-based designs. Until the W3C fixes this aspect of CSS, tables will save you a lot of headaches. Your design will still be valid HTML and, let's face it, none of your users will complain about the usage of tables on your site. box-sizing: border-box (forcing browsers to use an intuitive box model) will also help a great deal in column-based designs.
Fuzztrek
Fuzztrek
This doesn't work for you?

TEST - left
TEST - right
<style type="text/css">#left { float: left; width: 150px; }</style>


Unless I misunderstood, this works in IE, Firefox, and Opera. Setting the right div's margin-left to the same width of the left div wouldn't be a bad idea either, should you want to place a background on the right div.
jbadams
jbadams
Ok, I'm an idiot. [embarrass]

I had the right div (non-fixed width) floating against the others for some reason, which was causing it to collapse to the size of it's content unless I defined a width. No idea why I didn't spot that one myself, guess I'd just been playing with that markup for too long.

Thanks everyone for the assistance though. [smile]

Quote:
Original posts by benryves and kanzler
[advising use of tables]

Heh, I'm one of those 'purists' who avoids tables like the plague when not displaying tabulated data. I personally think the markup looks a lot cleaner without them, and as an added bonus my filesize is just that little bit smaller as well. If the hacks required to do the layout without them got overly out of hand then I'd resort to tables, but thus far I've still got hack-free markup, so I'm happy to continue trying to avoid them.
- Jason Astle-Adams
Sander
Sander
Quote:
Original post by Fuzztrek
Unless I misunderstood, this works in IE, Firefox, and Opera. Setting the right div's margin-left to the same width of the left div wouldn't be a bad idea either, should you want to place a background on the right div.


It stops working as soon as you add a margin to either of the top boxes (which I had when I played with some markup to come up with a simple solution -- to no effect).

Sander
Sander
Quote:
Original post by thevdo
I refer to the layouts often.


Yes, because they were posted a day ago...

There's a time and a place to pimp your own articles. Resurrecting dead threads isn't one of them.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.