I’m trying to make a ‘slide-out’ div that slides out when out hover over it. What I want to happen is that I want the left div to push the right div off into oblivion, but not below the div, but to the right.
Does anyone know why this happens?
Here is my script:
.container {
width: 796px;
background-color: yellow;
overflow:hidden;
}
.left {
display:none;
float: left;
width: 256px;
background: green;
}
.right {
float: right;
width: 796px;
height: 100%;
background-color: red;
}
Here is a live demo
click ‘colorbox’, then ‘show left div’.
Thank you everyone! :))))
Assuming your
.leftand.rightare within.containerthe reason one gets pushed down is because there is not enough space.You have set a
width:796pxfor the.containerand so the children i.e..leftand.rightwould need to add up to796px. At the moment they add up to1052pxand so one of them is pushed down as they cannot fit side by side.EDIT : Using inner container method mentioned in my comments below and in @Matteo’s answer you need to adjust the following css.
The reason it needs to be
1396pxis because it needs to be large enough that when.leftis expanded to600pxthat.rightat769pxcan still fit beside it. Then changing tofloat:leftis necessary so that there is no gap between the.leftand.rightand it remains visible when it is pushed sideways.