translateX()
translateX()函数表示在二维平面上水平方向移动元素。 其结果的数据类型是<transform-function>
。
注意: translateX(tx)
等同于 translate(tx, 0) 或者 translate3d(tx, 0, 0)。
语法
translateX(t)
参数
t
- 代表了向量平移的横坐标长度
<length>
。
ℝ2空间中的笛卡尔坐标 | 在ℝℙ2上的投影坐标 | 在ℝ3上的笛卡尔坐标 | 在ℝℙ3上的投影坐标 |
---|---|---|---|
在ℝ2 空间中的平移并非线性变化,因此不能表示为笛卡尔坐标矩阵。 |
|||
[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); /* 等同于 translate(10px) */
background-color: pink;
}
结果
标准化说明
标准 | 状态 | 备注 |
---|---|---|
CSS Transforms Level 1 translateX() |
Working Draft | 原始定义 |
浏览器兼容性
请前往数据类型<transform-function>
的页面以查看兼容性信息。