Generally when people are trying to animate display: none
what they really want is:
- Fade content in, and
- Have the item not take up space in the document when hidden
Most popular answers use visibility
, which can only achieve the first goal, but luckily it's just as easy to achieve both by using position
.
Since position: absolute
removes the element from typing document flow spacing, you can toggle between position: absolute
and position: static
(global default), combined with opacity
. See the below example.
.content-page {
position:absolute;
opacity: 0;
}
.content-page.active {
position: static;
opacity: 1;
transition: opacity 1s linear;
}