Alex Rivera | Logout

Getting left and right floats to overlap instead of stack

Asked 2012-05-04T12:43:34.317
12

This is easier to show than explain: http://jsfiddle.net/gN4VZ/

enter image description here

Is it possible to have my right-floated content (blue) overlap my left-floated content (red) instead of stack below it when the two combine to exceed the container width?

Edit
Report

1 Answer

2

Use absolute positioning with the .box class set to position:relative.

http://jsfiddle.net/gN4VZ/1/

Note that I had to set a height on each .box so that it wouldnt overlap top/bottom.

your new CSS would be

.bar {
    border:solid 1px black;
    color:white;
    position:relative;
    height:40px;
}
.clear {
    clear:both;
}
.left-bar {
    background:red;
    height:40px;
    position:absolute;
    left:0;
}
.right-bar {
    background:blue;
    position:absolute;
    right:0;
    height:40px;
}​

as suggested by My Head Hurts, you could just position the right one, which eliminates the need for the height on the outer div.

http://jsfiddle.net/gN4VZ/2/

answered 2012-05-04T12:48:38.963

Your Answer