When utilizing the fade functions in JQuery, an element that initially has 'display: none' and is then faded out will have JQuery inject 'display: block' when faded in.
In a flexbox layout, this can cause the element to wrap to the next line.
If I remove display:flex
from the parent container, it behaves as intended.
Is there a way to remove display:flex
only from specific elements that should be hidden initially?
One workaround is to use:
$('el').fadeIn().css('display','inline-block');
However, this approach may not be suitable for this situation. Any alternative suggestions?
Check out the demo below:
$('#clickme').click(function() {
$('#test').fadeToggle();
return false;
});
#flex {
display: flex; /* BREAKS JQUERY FADE, JQUERY INJECTS DISPLAY:BLOCK; */
flex-direction: column;
}
#main {
flex: 1;
}
.hidden {
display: none;
}
<script type="text/javascript" src="//code.jquery.com/jquery-3.1.1.min.js"></script>
<body id="flex">
<div id="main">
<span class="tools">
<a class="a" href="" id="clickme">Click Me</a>
<span id="test" class="hidden">I should be inline!</span>
</span>
</div>
</body>
If you remove display:flex
from #flex
, the behavior is as desired.