translateX()

translateX()CSS関数で、要素を二次元平面上の水平方向で再配置します。結果は <transform-function> データ型になります。

メモ: translateX(tx)translate(tx, 0) または translate3d(tx, 0, 0) と等価です。

構文

css

/* <length-percentage> values */
transform: translateX(200px);
transform: translateX(50%);

<length-percentage>

変換ベクトルの横座標を表す <length> または <percentage> です。パーセント値は transform-box プロパティで定義される参照ボックスの幅からの相対値です。

ℝ^2 のデカルト座標 ℝℙ^2 の同次座標 ℝ^3 のデカルト座標 ℝℙ^3 の同次座標

ℝ^2 では線形変換ではないので、デカルト座標の行列で表すことはできない。

1 0 t 0 1 0 0 0 1 1 0 t 0 1 0 0 0 1 1 0 0 t 0 1 0 0 0 0 1 0 0 0 0 1
[1 0 0 1 t 0]

形式文法

css

translateX(<length-percentage>)

HTML

html

<div>Static</div>
<div class="moved">Moved</div>
<div>Static</div>

CSS

css

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

.moved {
  transform: translateX(10px); /* translate(10px) と等価 */
  background-color: pink;
}

結果

仕様書

Specification
CSS Transforms Module Level 1
# funcdef-transform-translatex

ブラウザーの互換性

BCD tables only load in the browser

関連情報