I want to create a transition effect on the parent div when the child div disappears without using display:none
My goal is to have a dynamically centered div that animates using CSS transitions only.
Here is my current approach.
document.querySelector('#one').onclick = function () {
document.querySelector('#two').classList.add("hidden")
}
#content {
transition: all 0.5s ease;
}
.centered {
position: fixed;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
#one, #two {
width: 300px;
height: 150px;
line-height: 150px;
text-align: center;
}
#one {
background-color: cyan;
}
#two {
background-color: magenta;
}
.hidden {
display:none;
}
<div id="content" class="centered">
<div id="one">PRESS ME</div>
<div id="two">TO MAKE ME DISAPPEAR</div>
</div>
UPDATE: The solution does not have to use display:none