前端 - 怎样让scale缩小的元素不占据原来的空间?
怪我咯
怪我咯 2017-04-17 11:47:13
0
7
916

demo在这 , https://jsfiddle.net/qk83j2wv/
使用scale(0.5)缩小一个元素,但缩小后的元素还是占据原来元素的大小空间,
怎样让那个元素缩小后的大小和所占据的空间一样大呢?

但外层元素还是以缩小前来布局的...

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(7)
小葫芦

I’m both a novice, so I don’t seem to have a solution, but I can locate the zoom point, transform-origin:left top, and use this to zoom from the upper left corner. As for the size, it’s still the original size. Just add overflow: hidden to the parent element

左手右手慢动作

transform will not cause rearrangement, which means that scaling and other operations on elements will not affect the layout of other elements. In this way, the performance of animations and other effects will be better. If you want to change the space occupied by an element while scaling, use zoom to scale.

Ty80

Put the transparent p of the same size below

刘奇

Hope it helps you
<style>

    #d1 {
    width:200px;
    height:60px;
    border:1px solid red;
    transform-origin:left top;
    }
#d1>span {
    display:block;
    font-size:32px;
    line-height:60px;
    background:#F90;
    }

</style>
<body>

<p id="d1">
<span>内容</span>
</p>
<span class="btn">点我</span>
<script>
    $(function(){
        var i = true;
    $('.btn1').click(function(){
    if(i){
        $('#d1').css({transform:'scale(0.5)'});
        i = false;    
    }else {
        $('#d1').css({transform:'scale(1)'});
        i = true;        
    }
    });
    })
</script>

</body>

迷茫

Try zoom

洪涛

Theoretically there is no solution. You have to try to adjust the overall layout to achieve the effect you want

阿神

Pure CSS can’t do it, embarrassing.
But there is an idea. You can use a parent element as a wrapper, then use JavaScript to calculate the height and width of the compute style, and then reduce it to 50% accordingly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template