translateX()
Summary
Transform function for a 2d translation which moves an element on the x-axis by the given value.
Syntax
translateX ( <translation-value> )
Parameters
translation-value
Value for the translation across the x-axis. Can be a length or a percentage value.
Examples
The example shows three div elements, that are transformed individually with the translateX() function.
- The translation of the first element moves it 10 pixels to the right along the x-axis.
- You can also provide a negative value. In this case, element-2 is moved 20 pixels to the left, in the negative direction on the x-axis.
- Using a percentage value of 50 percent moves element-3 in x-direction by a value which matches 50 percent of the element-3’s width. In this case element-3 has a 100 pixel width, so it is moved 50 pixels to the right.
.element-1 {
transform: translateX(10px);
}
.element-2 {
transform: translateX(-20px);
}
.element-3 {
transform: translateX(50%);
}
See also
Related articles
Transforms
translateX()
External resources
- CSS Transforms Module, Level 3, Section 13.1
- Mathematical Description of Transform Functions
- Hands On: 2D Transforms
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]