How can I remove the unwanted whitespace in following example?
Note 1. that there should not be any red color, because #red is parent of two other #green and #blue.
Note 3. both #green and #blue have unknown height.
Note 2. #blue have an extera “top: -10px” css property, so it comes 10px up, but the parent element(#red) will not resize verticaly to fit new positions
<html>
<head>
<style>
#red{width: 500px;background: red;height: auto;}
#green{width: 500px;background: green;position: relative;float: left;}
#blue{width: 500px;background: blue;top:-7px;position: relative;float: left;}
.clear{clear: both;}
</style>
</head>
<body>
<div id="red">
<div id="green">Green<br>Green<br>Green<br>Green<br>Green</div>
<div id="blue">Blue<br>Blue<br>Blue<br>Blue<br>Blue</div>
<div class="clear"></div>
</div>
</body>
</html>
I don’t understand why you are floating things which are the same width as the parent. Also, using
position: relativehere is not at all necessary. Here’s a much simpler way to achieve exactly what you are talking about:View the jsFiddle.