translateX()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

Die translateX() CSS Funktion positioniert ein Element auf der 2D-Ebene horizontal neu. Das Ergebnis ist ein <transform-function> Datentyp.

Probieren Sie es aus

Hinweis: translateX(tx) ist gleichbedeutend mit translate(tx, 0) oder translate3d(tx, 0, 0).

Syntax

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

Werte

<length-percentage>

Ist ein <length> oder <percentage>, das die Abszisse (horizontale, x-Komponente) des Translationsvektors [tx, 0] darstellt. Im kartesischen Koordinatensystem repräsentiert es die Verschiebung entlang der x-Achse. Ein Prozentwert bezieht sich auf die Breite des durch die transform-box Eigenschaft definierten Referenzrahmens.

Kartesische Koordinaten auf ℝ^2 Homogene Koordinaten auf ℝℙ^2 Kartesische Koordinaten auf ℝ^3 Homogene Koordinaten auf ℝℙ^3

Eine Translation ist keine lineare Transformation in ℝ^2 und kann nicht durch eine Matrix in kartesischen Koordinaten dargestellt werden.

(10t010001)\left( \begin{array}{ccc} 1 & 0 & t \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right)
(10t010001)\left( \begin{array}{ccc} 1 & 0 & t \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right)
(100t010000100001)\left( \begin{array}{cccc} 1 & 0 & 0 & t \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array} \right)
[1 0 0 1 t 0]

Formale Syntax

<translateX()> = 
translateX( <length-percentage> )

<length-percentage> =
<length> |
<percentage>

Beispiele

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); /* Equal to translate(10px) */
  background-color: pink;
}

Ergebnis

Spezifikationen

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

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
translateX()

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch