代码之家  ›  专栏  ›  技术社区  ›  Nadav

flexbox下的缩放转换在chrome和firefox中的呈现方式不同

  •  0
  • Nadav  · 技术社区  · 7 年前

    我想将div居中,然后缩放(通过transorm:scale)使其更大。

    我用flexbox使div居中。 我想使用整个视图空间,所以我给了html和body元素100%的高度。

    在firefox中它呈现得很好。 然而,在chrome中,内部div的缩放似乎会导致body元素溢出,并出现一个垂直滚动条。

    如果你在chrome和firefox中运行下面的代码片段,你会注意到不同之处:垂直滚动条只在chrome中出现。我想让这个在chrome中看起来就像在firefox中一样(没有滚动条)。

    有人能帮我弄清楚吗?

    html {
      height: 100%;	  
      background-color: black;     
    }
    
    body {
      height: 100%;
      display: flex;
      overflow: auto;
      margin: 0;
      background-color: antiquewhite;
    }
    
    div {
      height: 50px;
      width: 50px;
      margin: auto;
      transform: scale(1.7);
      background-color: blue;
    }
    <html>
      <body>
        <div>
        </div>
       </body>
     </html>
    1 回复  |  直到 7 年前
        1
  •  2
  •   Temani Afif    7 年前

    而不是保证金 align-items / justify-content 使元素居中。Chrome似乎也扩大了导致此问题的利润率:

    html {
      height: 100%;
      background-color: black;
    }
    
    body {
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0;
      background-color: antiquewhite;
    }
    
    div.box {
      height: 50px;
      width: 50px;
      transform: scale(1.7);
      background-color: blue;
    }
    <div class="box">
    </div>