Apply the negative margin to the bottom of the float and it will drag the element underneath upwards.
Code:
.topleft, .topright {
float:left;
height:300px;
background-color:red;
width:150px;
overflow:auto;
margin-bottom:-40px;
}
.top {
padding-left:30px;
}
.top:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.bottom {
height:50px;
width:150px;
background-color:green;
position:relative;
}
Add position:relative to .bottom if you want the element in front.
You can't use a negative top margin on elements under a float because the margins slide under the float until they reach the containing block. This drags the background upwards but of course the content must still clear the float and stays where it was.
Margins, backgrounds and borders will always slide under the float until they reach the containing block but the foreground content (text and images) will still be repelled by the float..
Bookmarks