Forum Moderators: not2easy
Cheers,
asp
<html>
<head>
<style type="text/css">
body{
padding: 0px;
}
.div1{
background-color: #CCCCCC;
width: 300px;
height: 50px;
float: left;
}
.div2{
background-color: #999999;
width: 400px;
height: 300px;
margin-left: 30px;
margin-top: 30px;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html>
div2 should wrap around div1 (well, as long as you have content in either one of them)... Try adding some random text and see what it looks like.
Another approach is to let div1 reside inside div2.
+----------+--------+
¦···DIV1···¦··DIV2··¦
+----------+········¦
¦···················¦
¦···DIV2············¦
+-------------------+
technically floating doesn't remove an element from the page flow
ok... I always thought that was the point of float?
As for wrapping around, why would div1 take a margin applied to div2 when it's not a child?
Adding in text, for me in Phoenix display as if div1 was a child of div2. Amazingly Opera 6 & Dreamweaver! are the only two displaying as I would have expected!
This was me playing as a prelude to moving to the layout below:
+-----------------+
¦·················¦
+----------+·······¦
¦···DIV1···¦·······¦
+----------+·······¦
¦·················¦
¦·················¦
¦···DIV2··········¦
+-----------------+
Cheers,
asp
1. The left outer edge of a left-floating box may not be to the left of the left edge of its containing block. An analogous rule holds for right-floating elements.
2. If the current box is left-floating, and there are any left floating boxes generated by elements earlier in the source document, then for each such earlier box, either the left outer edge of the current box must be to the right of the right outer edge of the earlier box, or its top must be lower than the bottom of the earlier box. Analogous rules hold for right-floating boxes.
3. The right outer edge of a left-floating box may not be to the right of the left outer edge of any right-floating box that is to the right of it. Analogous rules hold for right-floating elements.
4. A floating box's outer top may not be higher than the top of its containing block.
5. The outer top of a floating box may not be higher than the outer top of any block or floated box generated by an element earlier in the source document.
6. The outer top of an element's floating box may not be higher than the top of any line-box containing a box generated by an element earlier in the source document.
7. A left-floating box that has another left-floating box to its left may not have its right outer edge to the right of its containing block's right edge. (Loosely: a left float may not stick out at the right edge, unless it is already as far to the left as possible.) An analogous rule holds for right-floating elements.
8. A floating box must be placed as high as possible.
9. A left-floating box must be put as far to the left as possible, a right-floating box as far to the right as possible. A higher position is preferred over one that is further to the left/right.
My senario would appear to be in direct violation of points 5,6 & 8 as div1 is the first element in the source.
asp
entire code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body{
padding: 0px;
}
.div1{
background-color: #CCCCCC;
width: 300px;
height: 50px;
float: left;
}
.div2{
background-color: #999999;
width: 400px;
height: 300px;
margin-left: 30px;
margin-top: 30px;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html> Cheers,
asp