简体   繁体   English

如何只缩放外部div而不是内部div

[英]how to Zoom only outer div not inner divs

I zoom a div using -moz-transform: scale(3.2) , but I only want to zoom the outer div and not the content (other divc) within that div. 我缩放div使用-moz-transform: scale(3.2)但我只想要放大该div内的外层div,而不是内容(其他DIVC)。

here is my code 这是我的代码

<div id="div1" style="-moz-transform: scale(3.2);" >
    <div id="div2">
        content
    </div>
</div>

Here I zoom the div1 , however div2 also zooms. 在这里我缩放div1 ,但div2也缩放。 I only want to zoom div1 but not div2 , meaning that the content of div2 will still be displayed as is. 我只是想放大div1但不div2 ,这意味着内容div2如仍然会显示出来。

You can add -moz-transform: scale(0.3125) to offset the parent scale. 您可以添加-moz-transform: scale(0.3125)来偏移父级。 Basically 0.3125 = 1 / 3.2 where 3.2 is the scale factor applied to the parent. 基本上0.3125 = 1 / 3.2其中3.2是应用于父母的比例因子。

 <div id="div1" style="-moz-transform: scale(3.2);-webkit-transform: scale(3.2); transform: scale(3.2);" > <div id="div2" style="-moz-transform: scale(.3125);-webkit-transform: scale(.3125); transform: scale(.3125);"> content </div> </div> 

You can invert a CSS scale by applying the reciprocal scale value on the child, eg if you have transform: scale(4); 您可以通过在子项上应用倒数比例值来反转CSS scale ,例如,如果您有transform: scale(4); on the parent you need scale 1/4 on the child: transform: scale(0.25); 在父母身上你需要在孩子身上得到1/4transform: scale(0.25); :

 div { width: 50px; height: 50px; } #div1 { transform: scale(4); border: 1px solid red; margin: 100px; } #div2 { transform: scale(0.25); border: 1px solid green; } 
 <div id="div1"> <div id="div2"> content </div> </div> 

In your case, you need transform: scale(0.3125); 在你的情况下,你需要transform: scale(0.3125); , the reciprocal of 3.2 . 3.2的倒数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM