I have an HTML and CSS as follows:
<div class="box" style="transform: scale(2);">
<div class="text">This is my text.</div>
</div>
How do I keep the text from scaling when the outer box does via animation?
On theory you can't. The scale will work on the entire element and inner child tree. But you can make it look like it's scaling up. Something like that (this method is lighter on the GPU and browser drawing):
<div class="box" style="position: relative">
<div class="box-block" style="position: absolute; transform: scale(2);"></div>
<div class="text">This is my text.</div>
</div>
So the idea is:
div will never be touched by the animation, because it's in a separate element.The structure could be improved, hope that gives you an idea. Cheers!
you need to scale the inner div by 1 divided by original scale (in your case 1 divided by 2 is 0.5):
<div class="box" style="transform: scale(2);">
<div class="text" style="transform: scale(0.5);">This is my text.</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With