blob: 027f1ba7184675c87bfaa6f9038b61bff23bbfed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
---
title: translateX()
slug: Web/CSS/transform-function/translateX
original_slug: Web/CSS/transform-function/translateX()
browser-compat: css.types.transform-function.translateX
---
{{CSSRef}}
La fonction CSS **`translateX()`** permet d'appliquer une translation en 2D. La valeur obtenue sera du type [`<transform-function>`](/fr/docs/Web/CSS/transform-function).

> **Note :** `translateX(tx)` est équivalent à `translate(tx, 0)` ou `translate3d(tx, 0, 0)`.
## Syntaxe
```css
/* Valeurs de type <length-percentage> */
transform: translateX(200px);
transform: translateX(50%);
```
### Values
- `<length-percentage>`
- : Une valeur exprimant une longueur (type [`<length>`](/fr/docs/Web/CSS/length)) ou un pourcentage ([`<percentage>`](/fr/docs/Web/CSS/percentage)) qui représente la composante horizontale du vecteur de translation. Lorsque la valeur est un pourcentage, elle est relative à la largeur de la boîte de référence définie par la propriété [`transform-box`](/fr/docs/Web/CSS/transform-box).
<table class="standard-table">
<thead>
<tr>
<th scope="col">Coordonnées cartésiennes sur ℝ<sup>2</sup></th>
<th scope="col">Coordonnées homogènes sur ℝℙ<sup>2</sup></th>
<th scope="col">Coordonnées cartésiennes sur ℝ<sup>2</sup></th>
<th scope="col">Coordonnées homogènes sur ℝℙ<sup>2</sup></th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">
<p>
Une translation n'étant pas une transformation linéaire pour ℝ<sup>2</sup>, elle ne peut pas être représentée par une matrice avec des coordonnées cartésiennes.
</p>
</td>
<td>
<math
><mfenced
><mtable
><mtr
><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mi>t</mi> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd
><mtd><mn>0</mn> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mn>1</mn></mtd></mtr
></mtable
></mfenced
></math
>
</td>
<td rowspan="2">
<math
><mfenced
><mtable
><mtr
><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mi>t</mi> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd
><mtd><mn>0</mn> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mn>1</mn></mtd></mtr
></mtable
></mfenced
></math
>
</td>
<td rowspan="2">
<math
><mfenced
><mtable
><mtr
><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mn>0</mn> </mtd><mtd><mi>t</mi> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd
><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr
><mtr
><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd
><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr
></mtable
></mfenced
></math
>
</td>
</tr>
<tr>
<td><code>[1 0 0 1 t 0]</code></td>
</tr>
</tbody>
</table>
### Syntaxe formelle
```css
translateX([`<length-percentage>`](/fr/docs/Web/CSS/length-percentage))
```
## Exemples
### HTML
```html
<div>Statique</div>
<div class="moved">Déplacé</div>
<div>Statique</div>
```
### CSS
```css
div {
width: 60px;
height: 60px;
background-color: skyblue;
}
.moved {
transform: translateX(10px); /* Équivalent à translate(10px) */
background-color: pink;
}
```
### Résultat
{{EmbedLiveSample("Exemples", 250, 250)}}
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}
## Voir aussi
- [`translate()`](/fr/docs/Web/CSS/transform-function/translate)
- [`translateY()`](/fr/docs/Web/CSS/transform-function/translateY)
- [`transform`](/fr/docs/Web/CSS/transform)
- [`<transform-function>`](/fr/docs/Web/CSS/transform-function)
|