How to scale a div without scaling content

前端 未结 3 2000
谎友^
谎友^ 2020-12-20 23:39

I have this div (id=\"myDiv\"), when the div is under css - scale all it\'s children are under scale as well. I need the div to enlarge but not the children, in a \"creative

3条回答
  •  轮回少年
    2020-12-21 00:18

    You need to calculate backwards for the child elements.

    For instance, you are scaling the div by 200% in the x axis...to reduce the children back to 100% you need to scale down to 50% (0.5)

    Ditto for the y-axis 300%...therefore 33% (0.3)

    CSS

    .scaled { /* the parent */
        transform: scale(2,3);
        transform-origin:top left;
     }
    
    .scaled * { /* the children */
       transform: scale(.5, .33); 
    }
    

    Jsfiddle Demo

    NOTE: As you can see there are transform-origin issues as well and other spacing issues youl will need to address.

提交回复
热议问题