Issue:
- Hover over the X and wait for the div to collapse completely.
- Move away from the X
- Notice how the div jumps to the bottom and then back up.
Inquiry:
How can I prevent text wrapping while expanding the div during animation? (Currently using delayed font-size, which is causing issues).
Limitations:
These constraints are in place due to the broader design of this snippet.
- Cannot disable wrapping on the
outer
div (except during the animation). - Unable to set fixed width or height to the
inner
div. - No use of JS allowed.
Additional Information:
For the hover state, I am utilizing white-space:nowrap
to prevent text wrapping while collapsing the div. Then, a delayed font-size
transition is used to avoid text wrapping while expanding the div again (since animating white-space
or display
is not feasible).
It seems like the font-size of 0 is momentarily lost at the beginning of the animation, explaining the initial jump.
.outer {
width: 300px;
overflow: hidden;
border: 1px solid red;
transition: width 2s;
}
.button {
padding: 0px 10px;
display:inline-block;
}
.outer:hover {
width: 30px;
white-space: nowrap;
}
.outer .inner {
font-size: 15px;
display:inline-block;
transition: font-size 0s 2s;
}
.outer:hover .inner {
font-size: 0px;
}
<div class="outer">
<div class="button">
X
</div>
<div class="inner">
This is the variable content of the box
</div>
</div>