views:

183

answers:

1

I am trying to build a layout which has a fixed width div and a liquid width div beside it :

<div id="main" style="width:100%; height:500px; background-color: #ccc;">
    <div id="right" style="float: right; width:100px; height:500px; background-color: red;">
    </div>
    <div id="left" style="float: right; width: auto; height:500px; background-color: orange;">
    </div>
</div>

the left div is not filling its width, also i want this div to fill whole main div when right div is not present, how can i do it ?

A: 

I think what you want is more like

<div id="main" ... >
  <div id="right" style="float: right; width: 100px;"> Will take up 100 px </div>
  <div id="left" style="margin-right: 100px;"> Will take up the rest </div>
</div>
levik
thnx. its working now, but is it possible to make the left div width fill whole main div when i remove the right div in this method?
Datis
@Datis: probably only with a javascript event, there's no if/else in CSS that would allow for conditional logic to be applied (unless it's in CSS3 and I just haven't come across it yet).
David Thomas
so in this case i should use tables or just write another css rule with separate HTML file ?
Datis
What do you mean by "remove"? If you're doing it dynamically, with Javascript, you can also dynamically change the style to not have the margin in that same bit of code, as @ricebowl said. But I don't think there's a pure CSS solution that would kick in if DOM were somehow modified.
levik
maybe i am not explaining it right, something like sidebar that is not in every page. if there is no sidebar the other div fill the whole area...
Datis
If there's no sidebar, skip the style attribute on the left div when generating the page on the server. That's the easiest solution, and the most robust.
levik