在线文档教程
CSS

translateX()

translateX()

translateX() CSS函数在2D平面中水平方向上重新定位元素。

注意: translateX(tx)相当于translate(tx, 0)translate3d(tx, 0, 0)

语法

translateX(t)

可能值

t是表示平移向量的横坐标的<length>值。

Cartesian coordinates on ℝ2Homogeneous coordinates on ℝℙ2Cartesian coordinates on ℝ3Homogeneous coordinates on ℝℙ3
A translation is not a linear transform in ℝ2 and cannot be represented using a matrix in the Cartesian coordinate system.10t01000110t010001100t010000100001

| 1 0 0 1 t 0 |

实例

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 background-color: pink; }

结果

另见

  • transform

  • <transform-function>