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
/* <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 dietransform-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. |
|
|
|
[1 0 0 1 t 0] |
Formale Syntax
<translateX()> =
translateX( <length-percentage> )
<length-percentage> =
<length> |
<percentage>
Beispiele
HTML
<div>Static</div>
<div class="moved">Moved</div>
<div>Static</div>
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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
translateX() |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support