How does css scale transform affect document flow?

后端 未结 1 1803
不知归路
不知归路 2021-01-12 10:22

I\'m really confused how scaling an element using css transforms affects document flow.

Consider this jsbin or this codepen since jsbin seems to have gone down where

相关标签:
1条回答
  • 2021-01-12 10:53

    CSS Transform does not affect document flow. The DOM element will occupy it's original position and dimensions within the page flow.

    So if you have 3 square div's of identical size, displayed inline in a row and apply a -webkit-transform: scale(2) to the center square, this square will scale up to 200% larger, scale from the center of its original position, and overlap both other squares.

    Reference example:

    http://jsfiddle.net/ypnEk/

    HTML:

    <div class="square one"></div>
    <div class="square two"></div>
    <div class="square three"></div>
    

    CSS:

    .square{
      margin-top:50px;
      width:50px;
      height:50px;
      display:inline-block;
    }
    
    .one{
      background:#222;
    }
    
    .two{
      background:#888;
      -webkit-transform: scale(2);
    }
    
    .three{
      background:#ccc;
    }
    
    0 讨论(0)
提交回复
热议问题