scaleY()

Baseline 已廣泛支援

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

scaleY() CSS 函式定義了一種沿 y 軸(垂直方向)調整元素大小的變換。其結果是一種 <transform-function> 資料型別。

試一試

transform: scaleY(1);
transform: scaleY(0.7);
transform: scaleY(1.3);
transform: scaleY(-0.5);
<section id="default-example">
  <img
    class="transition-all"
    id="example-element"
    src="/shared-assets/images/examples/firefox-logo.svg"
    width="200" />
</section>

它透過一個常數因子來修改每個元素點的縱座標(垂直方向的 y 座標),但縮放因子為 1 時除外,此時該函式是恆等變換。這種縮放不是各向同性的,元素的角度也不會被保留。scaleY(-1) 定義了一個軸對稱變換,對稱軸為一條穿過原點(由 transform-origin 屬性指定)的水平軸。

備註: scaleY(sy) 等價於 scale(1, sy)scale3d(1, sy, 1)

transform: rotateX(180deg); === transform: scaleY(-1);

語法

css
scaleY(s)

s

是一個 <number>,表示應用於元素每個點的縱座標(垂直方向的 y 座標)的縮放因子。

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

正式語法

<scaleY()> = 
scaleY( <number> )

示例

HTML

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

CSS

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

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

結果

規範

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

瀏覽器相容性

另見