scaleX()

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

scaleX() CSS 函式定義了一個變換,用於沿著 x 軸(水平方向)調整元素的大小。其結果是 <transform-function> 資料型別。

試一試

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>

它透過一個常數因子修改每個元素點的橫座標(水平,x 座標),除非縮放因子為 1,在這種情況下,該函式是恆等變換。縮放不是各向同性的,並且元素的角度通常不守恆,除了 90 度的倍數。scaleX(-1) 定義了一個軸對稱,垂直軸穿過原點(由 transform-origin 屬性指定)。

注意:scaleX(sx) 等價於 scale(sx, 1)scale3d(sx, 1, 1)

語法

css
scaleX(s)

s

一個 <number>,表示應用於元素每個點的橫座標(水平,x 座標)的縮放因子。

笛卡爾座標,在 ℝ^2 齊次座標,在 ℝℙ^2 笛卡爾座標,在 ℝ^3 齊次座標,在 ℝℙ^3
(s001)\left( \begin{array}{cc} s & 0 \\ 0 & 1 \end{array} \right)
(s00010001)\left( \begin{array}{ccc} s & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right)
(s00010001)\left( \begin{array}{ccc} s & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right)
(s000010000100001)\left( \begin{array}{cccc} s & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array} \right)
[s 0 0 1 0 0]

正式語法

<scaleX()> = 
scaleX( <number> )

示例

HTML

html
<div>Normal</div>
<div class="scaled">Scaled</div>

CSS

css
div {
  width: 80px;
  height: 80px;
  background-color: skyblue;
}

.scaled {
  transform: scaleX(0.6);
  background-color: pink;
}

結果

規範

規範
CSS 變換模組級別 1
# funcdef-transform-scalex

瀏覽器相容性

另見