--- title: translate3d() slug: Web/CSS/transform-function/translate3d tags: - CSS - CSS 函数 - CSS 变换 - 参考 translation_of: Web/CSS/transform-function/translate3d() original_slug: Web/CSS/transform-function/translate3d() ---
translate3d() CSS 函数在3D空间内移动一个元素的位置。这个移动由一个三维向量来表达,分别表示他在三个方向上移动的距离。
translate3d(tx, ty, tz)
| Cartesian coordinates on ℝ2 | Homogeneous coordinates on ℝℙ2 | Cartesian coordinates on ℝ3 | Homogeneous coordinates on ℝℙ3 |
|---|---|---|---|
|
此变换适用于3D空间,并不适用于这两种情况。 |
平移不是ℝ3中的线性变换,不能使用笛卡尔坐标矩阵表示。 |
||
<p>foo</p> <p class="transformed">bar</p> <p>foo</p>
p {
width: 50px;
height: 50px;
background-color: teal;
}
.transformed {
transform: perspective(500px) translate3d(10px,0px,0px);
/* equivalent to perspective(500px) translateX(10px)*/
background-color: blue;
}
{{EmbedLiveSample("Using_a_single_axis_translation","100%","250")}}
<p>foo</p> <p class="transformed">bar</p> <p>foo</p>
p {
width: 50px;
height: 50px;
background-color: teal;
}
.transformed {
transform: perspective(500px) translate3d(10px,0px,100px);
background-color: blue;
}
{{EmbedLiveSample("Combining_z-axis_and_x-axis_translation","100%","250")}}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName("CSS Transforms 2", "#funcdef-translate3d", "translate3d()")}} | {{Spec2("CSS Transforms 2")}} | Initial definition |
有关兼容性信息,请参阅<transform-function>的兼容性信息。