I want to have a division disappear by shrinking smoothly.
I tried doing this by making the font-size change to 0 with transition set to 1s.
When I do this the font gets some some minimum size, then freezes and then disappears causing a jerky jumpy change to the layout.
I would like it to shrink smoothly like it does when transform:scale(0)
is set, but the layout doesn’t change when I do this.
Here is a jsFilddle example:
https://jsfiddle.net/3e0ajpzL/1/
css
.shown {
font-size: 2em;
transition: 1s;
cursor: pointer;
}
.hidden {
font-size: 0;
}
HTML
Top
<div onclick=hide(this) id=target class=shown>
Click to make me go away<br>
-----------------<br>
more lines<br>
make <br>
it <br>
Worse
</div>
<div style=cursor:pointer onclick=restore()>
Click to bring him back
</div>
JS
function hide(ele) {
ele.classList.toggle("hidden");
}
function restore() {
document.getElementById("target").classList.toggle("hidden");
}
EDIT
This appears to not happen on the edge browser. I am using chrome browser.
2
Answers
As
A Haworth
pointed out, in some browsers you can set a minimum font size. I appear to have done this on my chrome browser. On the current chrome browser you can get to this setting by going to setting>appearance>custom fonts or by going to chrome://settings/fontsSet the minimum font size to the lowest setting to the lowest setting.
I think you need to add
line-height