Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scale a container to match its scaled (or otherwise transformed) content?

I have a <div>, inside of which some complicated content is rendered with a scale transform applied. My problem is that the <div> takes up the same space that it would have taken even if no transform was applied. I've made a jsFiddle snippet to illustrate what I mean.

I think I can understand why the behavior is like this, but is there any way to make it so that the container takes as much space as its content with scaling (and other transforms, if possible) applied?

I should note that explicitly setting the width and height of the <div> outside affects the contents of the scaled text (and this is not desired behavior in my case). Putting the scaled content in an <iframe> is something I'd like to avoid.

like image 279
Theodoros Chatzigiannakis Avatar asked Nov 12 '22 02:11

Theodoros Chatzigiannakis


1 Answers

Without resorting to Javascript, there isn't any way to do this, I don't think. CSS transforms don't affect layout flow for elements near the transformed elements, they only change the coordinate system within that element; so children are affected, but not parents or siblings (MDN has some more detail on this).

There's a great answer here that might be a JS-based partial solution for you: https://stackoverflow.com/a/10913299/2524360

like image 172
Bryson Gilbert Avatar answered Nov 15 '22 00:11

Bryson Gilbert