I have two divs beside one another. With the click of a button, the div on the left collapses to the left leaving only the div on the right. Since the div on the right is width:100%;, it fills the space left behind by the collapsed left div. The only problem is that while the div is collapsing/the CSS transition is in progress, the right div disappears for a moment and I can't figure out why.
HTML
<div>
<div id="demo" class="collapse show width">
<aside>
</aside>
</div><!--COLLAPSE-->
<main>
<button role="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo">
simple horizontal collapsible
</button>
<div class="sample">
Some TExt
</div>
</main>
</div>
CSS
html {
height: 100%
}
body {
height: 100%;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
background: gray;
}
a {
color: #00B7FF;
}
.collapse {
visibility: hidden;
}
.collapse.show {
visibility: visible;
display: block;
}
.collapsing {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition-property: height, visibility;
transition-property: height, visibility;
-webkit-transition-duration: 0.45s;
transition-duration: 0.45s;
-webkit-transition-timing-function: ease;
transition-timing-function: ease;
}
.collapsing.width {
-webkit-transition-property: width, visibility;
transition-property: width, visibility;
width: 0;
height: auto;
}
aside {
height: 100vh;
width: 250px;
background-color: white;
/*border-right:1px solid black;*/
display: block;
float: left;
}
.sample {
margin-top: 100px;
text-align: center;
}
main {
width: 100%;
height: 100vh;
background-color: pink;
display: inline;
}
LIVE EXAMPLE
https://jsfiddle.net/djjvqtop/1/
This occurs in all browsers. Is there a way to prevent this?
The problem is caused by a fact that adding overflow: hidden
changes the height of #demo
. Initially it is 0, because it contains nothing but the float element. Class .collapsing
adds overflow: hidden
, which makes it expand to contain the float. So #demo.collapsing
has the height of <aside>
and the <main>
element is below it and out of sight.
One solution is to make #demo
also float left.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With