scaleX() CSS 函数将每个元素点的横坐标修改为一个常数因子,除了该比例因子为 1,在这种情况下,函数是身份变换。缩放不是各向同性的,并且元素的角度不保守。
CSS 演示:scaleX()
transform: scaleX(1);
transform: scaleX(0.7);
transform: scaleX(1.3);
transform: scaleX(-0.5);
<section id="default-example">
<img
class="transition-all"
id="example-element"
src="/shared-assets/images/examples/firefox-logo.svg"
width="200" />
</section>
scaleX(sx) 是 scale(sx, 1) 或 scale3d(sx, 1, 1) 的一个速记/缩写。
[!NOTE]
scaleX(-1)定义一个轴向对称性,它具有一个垂直轴通过原点(由 transform-origin 属性规定)。
语法
scaleX(s)
值
- s
- : Is a <number> representing the scaling factor to apply on the abscissa of each point of the element.
<table class="standard-table"> <thead> <tr> <th scope="col">Cartesian coordinates on ℝ<sup>2</sup></th> <th scope="col">Homogeneous coordinates on ℝℙ<sup>2</sup></th> <th scope="col">Cartesian coordinates on ℝ<sup>3</sup></th> <th scope="col">Homogeneous coordinates on ℝℙ<sup>3</sup></th> </tr> </thead> <tbody> <tr> <td colspan="1" rowspan="2"> <math ><mfenced ><mtable ><mtr><mtd>s</mtd><mtd>0</mtd></mtr> <mtr><mtd>0</mtd><mtd>1</mtd></mtr></mtable ></mfenced ></math > </td> <td> <math ><mfenced ><mtable ><mtr>s<mtd>0</mtd><mtd>0</mtd></mtr ><mtr>0<mtd>1</mtd><mtd>0</mtd></mtr ><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable ></mfenced ></math > </td> <td colspan="1" rowspan="2"> <math ><mfenced ><mtable ><mtr>s<mtd>0</mtd><mtd>0</mtd></mtr ><mtr>0<mtd>1</mtd><mtd>0</mtd></mtr ><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable ></mfenced ></math > </td> <td colspan="1" rowspan="2"> <math ><mfenced ><mtable ><mtr>s<mtd>0</mtd><mtd>0</mtd><mtd>0</mtd></mtr ><mtr>0<mtd>1</mtd><mtd>0</mtd><mtd>0</mtd></mtr ><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd><mtd>0</mtd></mtr ><mtr ><mtd>0</mtd><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr ></mtable ></mfenced ></math > </td> </tr> <tr> <td><code>[s 0 0 1 0 0]</code></td> </tr> </tbody> </table>
示例
Without changing the origin
HTML
<p>foo</p>
<p class="transformed">bar</p>
CSS
p {
width: 50px;
height: 50px;
background-color: teal;
}
.transformed {
transform: scaleX(2);
background-color: blue;
}
结果
Without_changing_the_origin
Translating the origin of the transformation
HTML
<p>foo</p>
<p class="transformed">bar</p>
CSS
p {
width: 50px;
height: 50px;
background-color: teal;
}
.transformed {
transform: scaleX(2);
transform-origin: left;
background-color: blue;
}
结果
Translating_the_origin_of_the_transformation
规范
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
