平面转换介绍
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>位移-基本使用</title>
- <style>
- .father {
- width: 500px;
- height: 300px;
- margin: 100px auto;
- border: 1px solid #000;
- }
-
- .son {
- width: 200px;
- height: 100px;
- background-color: pink;
- transition: all 0.5s;
- }
-
-
- .father:hover .son {
-
-
-
-
-
-
-
-
-
-
- transform: translateY(100px);
- }
- </style>
- </head>
-
- <body>
- <div class="father">
- <div class="son"></div>
- </div>
- </body>
-
- </html>
-
使用translate快速实现绝对定位的元素居中
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>绝对定位元素居中效果</title>
- <style>
- .father {
- position: relative;
- width: 500px;
- height: 300px;
- margin: 100px auto;
- border: 1px solid #000;
- }
-
- .son {
- position: absolute;
- left: 50%;
- top: 50%;
-
-
-
- transform: translate(-50%, -50%);
-
- width: 203px;
- height: 100px;
- background-color: pink;
- }
- </style>
- </head>
- <body>
- <div class="father">
- <div class="son"></div>
- </div>
- </body>
- </html>
-
使用translate实现元素位移效果