translateX()

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

試してみましょう

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

構文

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

<length-percentage>

変換ベクトルの横座標を表す <length> または <percentage> です。直交座標系では X 座標の移動量をを表します。パーセント値は 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

関連情報