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 |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
translateX() |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.