tags:

views:

664

answers:

4

Is there a way to make divs side by side?

I want the layout

------------
|Header div|
------------
|  |       |
|ul|iframe |
|  |       |

But if the iframe is visible:hidden/collapsed the <ul> will take all the space

------------
|Header div|
------------
|          |
|ul        |
|          |

If I make the ul float left, then the ul will not have width:auto and if I make the iframe position:absolute the ul will always exapand thru the entire site.

All the sites that shows this use ul with a margin. But then the ul will have the margin if the iframe isnt there

A: 

Wrap the iframe in a div to handle the iframe position. Reduce the div's padding to 0.

+2  A: 

If you float the iframe to the right of the ul, then the content of the ul will be able to fill the full width when it is removed (or the display style is set to none). Since altering the visibility style does not affect layout, changing that will accomplish nothing.

<div>Header</div>
<iframe src="http://www.google.com/" style="width:80%;float:right">
</iframe>
<ul>
  <li>Left column / main column</li>
  <li>A list</li>
  <li>of things</li>
</ul>
Shog9
This will almost make it work. but the problem is that the ul is 100% of the site even when the iframe is on the site.<ul style="background-color: Yellow;">The yellow take width: 100%
Christian Johansson
Yes. But the content of the ul will not take up the full width.
Shog9
A: 

Maybe this will clear some things.

I want the site look like the example below. But the li borders should stop at 80% when the iframe is on the site. But when the site doesn´t render the iframe the li border should stop at 100%.

I can do this by changing the style when I'm not render the iframe. But it would be nice if I can do this in pure css.

Im sure this is possible and thats why I want to do it this way.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Test</title>
</head>
<body>
<div>Header</div>
<iframe src="http://www.google.com/" style="width:20%;float:right">
</iframe>
<ul>
  <li style="border: solid 1px Yellow;">Left column / main column</li>
  <li style="border: solid 1px Yellow;">A list</li>
  <li style="border: solid 1px Yellow;">of things</li>
</ul>
</body>
</html>
Christian Johansson
Of course you can implement this quite easily using tables, although using tables for layout is discouraged.
Perspx
Also, this data would have been better put in the question: see the "edit" link.
Kent Fredric
O sorry, this was my first post. I will learn to use the edit link.
Christian Johansson
A: 
I solved it. By setting overflow:auto on the ul element!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Test</title>
</head>
<body>
<div>Header</div>
<iframe src="http://www.google.com/" style="width:20%;float:right">
</iframe>
<ul style="overflow: auto;">
  <li style="border: solid 1px Yellow;margin: 5px;">Left column / main column</li>
  <li style="border: solid 1px Yellow;margin: 5px;">A list</li>
  <li style="border: solid 1px Yellow;margin: 5px;">of things</li>
</ul>
</body>
</html>
Christian Johansson