Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

scale()

CSS 函数 scale() 用于修改元素的大小。可以通过向量形式定义的缩放值来放大或缩小元素,同时可以在不同的方向设置不同的缩放值。

该变换通过一个二维向量确定在一个方向缩放的多少。如果缩放向量的两个坐标是相等的,那么所讲是均等的,或者说是各向同的,同时元素的形状是被保持的。这种情况下进行的是位似变换。

当坐标值处于区间 [-1, 1] 之外时,该变换将在相应的坐标方向上放大该元素,当处在区间之中时,该变换将在相应的坐标方向上缩小该元素。当值为1时将不进行任何处理,当为负数时,将进行像素点反射之后再进行大小的修改。

scale() 仅适用于在欧几里得平面(二维平面)上的变换。如果需要进行空间中的缩放,必须使用 scale3D() 。

语法

scale(sx)

scale(sx, sy)

sx
<number>,表示缩放向量的横坐标。
sy
<number> ,表示缩放向量的纵坐标。如果未设置,则他的默认值被设置为 sx。 从而使得元素在保持原有形状下均等缩放
2上的笛卡尔坐标变换 ℝℙ2上的齐次坐标变换 3上的笛卡尔坐标变换 ℝℙ3上的齐次坐标变换
sx0 0sy sx000sy0001 sx000sy0001 sx0000sy0000100001
[sx 0 0 sy 0 0]

示例

单一维度缩放

HTML

<p>foo</p>
<p class="transformed">bar</p>

CSS

p { 
  width: 50px;
  height: 50px;
  background-color: teal;
}

.transformed {
  /* 等同于变换: scaleX(2) scaleY(2);*/
  transform: scale(2);
  background-color: blue;
}

结果

在X和Y两个维度缩放并移动缩放中心

HTML

<p>foo</p>
<p class="transformed">bar</p>

CSS

p { 
  width: 50px;
  height: 50px;
  background-color: teal;
}

.transformed {
  /* 等同于 scaleX(2) scaleY(0.5) */
  transform: scale(2, 0.5);
  transform-origin: left;
  background-color: blue;
}

结果

文档标签和贡献者

 此页面的贡献者: Jack-Q
 最后编辑者: Jack-Q,