tags:

views:

17

answers:

1

I have two floated divs which appear side by side as they should, however I want to have div 1 stretch to the full width of its container when div 2 is not present. I've tried doing this by removing the width of div 1 (while leaving the width of div 2) however this breaks the float and pushes div two to a new line.

Can anyone advise me how I can achieve a div which auto-stretches to the full width of the container when the second div is not present?

A: 

Can't you just have server-side code that generates an extra class name on one of the divs to be say, 'wide-float' when the other isn't present?

meder
Hi Thanks for replying. The problem is that I need to specify a width for Div 1. This is fine when Div 2 is present, but when it isn't Div 1 remains at that fixed width, whereas I'd need it to stretch to the entire container width.
Michael
As you suggested I was able to write a server side command using a conditional statement (in a Joomla install) which deploys an extra class name based on whether the Div 2 module is loaded. This is a pretty solid solution. I am still curious to know if there's a natural way to perform this with CSS though, as it seems that this would be a pretty common thing in web design. Does anyone know?
Michael