css transtorm scale 和 zoom 区别

479 阅读1分钟

transtorm scale 不缩放空间,对span等inline 元素无法缩放, zoom 缩放空间,适用于所有元素,兼容性不好。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .wrap {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 300px;
      height: 300px;
      border: 1px solid red;
      font-size: 33px;
    }
    .item  {
      transform: scale(0.5);
    }

    .wrap1 {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 300px;
      height: 300px;
      border: 1px solid red;
      font-size: 33px;
    }
    .item1  {
      zoom: 0.5;
    }
  </style>
</head>
<body>
  <div  class="wrap">
    aa
    <span class="item">bbbbbbb</span>
    cc
  </div>

  <div  class="wrap1">
    aa
    <span class="item1">bbbbbbb</span>
    cc
  </div>
</body>
</html>