transform: translate(x, y);


 

 

 

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
/* 移動盒子的位置: 定位 盒子的外邊距 2d轉換移動 */

div {
width: 200px;
height: 200px;
background-color: pink;
/* x就是x軸上移動位置 y 就是y軸上移動位置 中間用逗號分隔*/
/* transform: translate(x, y); */
/* transform: translate(100px, 100px); */
/* 1. 我們如果只移動x坐標 */
/* transform: translate(100px, 0);
transform: translateX(100px); */
/* 2. 我們如果只移動y坐標 */
transform: translate(0, 100px);
transform: translateY(100px);
}

div:first-child {
transform: translate(30px, 30px);
}

div:last-child {
background-color: purple;
}
</style>
</head>

<body>
<div></div>
<div></div>
</body>

</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM