transform scale keeps the original space around the scaled element

前端 未结 3 2186

I have two nested divs. The inner one is transform: scale(0.5).

Both are display: inline-block;.

What I need to happen is

3条回答
  •  春和景丽
    2021-02-18 22:38

    A brutal way would be to virtually reduce space needed by element.

    Your example shows a known width & height, so it makes it easy. else you would need a javascript method.

    .box_1 {
        width:  300px;
        height: 300px;
        transform: scale(0.5);
        transform-origin: left top;
      margin-bottom:-150px;
      margin-right:-150px;
    }
    

    https://jsfiddle.net/0bc4sxk3/1/

    Scaling up would mean positive margins.

    Transform only happens at screen, elements still use initial room and place needed in the flow of the document.

提交回复
热议问题