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.
translateX() 函数表示在二维平面上水平方向移动元素。其结果的数据类型是<transform-function>
。
备注: translateX(tx)
等同于 translate(tx, 0) 或者 translate3d(tx, 0, 0)。
语法
css
translateX(t)
参数
示例
HTML
html
<div>Static</div>
<div class="moved">Moved</div>
<div>Static</div>
CSS
css
div {
width: 60px;
height: 60px;
background-color: skyblue;
}
.moved {
transform: translateX(10px); /* 等同于 translate(10px) */
background-color: pink;
}
结果
规范
Specification |
---|
CSS Transforms Module Level 1 # funcdef-transform-translatex |
浏览器兼容性
BCD tables only load in the browser