transform:translate() …… 要素の表示位置を移動させる
transform:translateX()
transform:translateY()
transform:translateZ()
transform:translate3d()







広告
transformプロパティのtranslate ()、translateX()、translateY()、translateZ()、translate3d()は、要素の表示位置を移動させる際に使用します。
- translate(X方向の距離, Y方向の距離)
- translate()関数では、X方向とY方向の距離で2D移動を指定します。
Y方向の距離は省略することができますが、この場合のY方向の距離は0となります。[tx, ty]
- translateX(X方向の距離)
- translateX()関数では、X方向の距離で移動を指定します。
- translateY(Y方向の距離)
- translateY()関数では、Y方向の距離で移動を指定します。
- translateZ(Z方向の距離)
- translateZ()関数では、Z方向の距離で移動を指定します。
translateZ()関数にはパーセンテージ値を指定することができないので注意してください。
もし、パーセンテージで値を指定しても0と同じになります。
- translate3d(X方向の距離, Y方向の距離, Z方向の距離)
- translate3d()関数では、X方向とY方向とZ方向の距離で3D移動を指定します。
Y方向とZ方向の距離は省略することができますが、この場合のY方向とZ方向の距離は0となります。[tx,ty,tz]
- 初期値
- none
- 適用対象
- ブロックレベル要素、インライン要素
- 値の継承
- しない
p.sample1, p.sample2, p.sample3, p.sample4, p.sample5 {background-color:limegreen;}
p.sample1 img {transform: translate(50px,20px);}
p.sample2 img {transform: translateX(50px);}
p.sample3 img {transform: translateY(20px);}
p.sample4 img {transform: translateZ(10px);}
p.sample5 img {transform: translate3d(50px,20px,10px);}
<html>
<head>
<link rel="stylesheet" href="sample.css"
type="text/css">
</head>
<body>
<p class="sample1">
translate(50px,20px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="sample2">
translateX(50px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="sample3">
translateY(20px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="sample4">
translateZ(10px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="sample5">
translate3d(50px,20px,10px)<br>
<img src="../images/kaeru.gif">
</p>
</body>
</html>
↓↓↓
translate(50px,20px)
translateX(50px)
translateY(20px)
translateZ(10px)
translate3d(50px,20px,10px)
p.prefix_sample1, p.prefix_sample2, p.prefix_sample3, p.prefix_sample4, p.prefix_sample5 {background-color:limegreen;}
p.prefix_sample1 img {
-moz-transform: translate(50px,20px);
-webkit-transform: translate(50px,20px);
-o-transform: translate(50px,20px);
-ms-transform: translate(50px,20px);
}
p.prefix_sample2 img {
-moz-transform: translateX(50px);
-webkit-transform: translateX(50px);
-o-transform: translateX(50px);
-ms-transform: translateX(50px);
}
p.prefix_sample3 img {
-moz-transform: translateY(20px);
-webkit-transform: translateY(20px);
-o-transform: translateY(20px);
-ms-transform: translateY(20px);
}
p.prefix_sample4 img {
-moz-transform: translateZ(10px);
-webkit-transform: translateZ(10px);
-o-transform: translateZ(10px);
-ms-transform: translateZ(10px);
}
p.prefix_sample5 img {
-moz-transform: translate3d(50px,20px,10px);
-webkit-transform: translate3d(50px,20px,10px);
-o-transform: translate3d(50px,20px,10px);
-ms-transform: translate3d(50px,20px,10px);
}
<html>
<head>
<link rel="stylesheet" href="sample.css" type="text/css">
</head>
<body>
<p class="prefix_sample1">
translate(50px,20px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="prefix_sample2">
translateX(50px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="prefix_sample3">
translateY(20px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="prefix_sample4">
translateZ(10px)<br>
<img src="../images/kaeru.gif">
</p>
<p class="prefix_sample5">
translate3d(50px,20px,10px)<br>
<img src="../images/kaeru.gif">
</p>
</body>
</html>
↓↓↓
translate(50px,20px)
translateX(50px)
translateY(20px)
translateZ(10px)
translate3d(50px,20px,10px)
広告