- <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;
- }
-
- /* 鼠标移入到父盒子,son改变位置 */
- .father:hover .son {
- transform: translate(200px, 100px);
-
- /* 百分比:参照盒子自身尺寸计算结果 */
- transform: translate(50%, 100%);
- transform: translate(-50%, 100%);
-
- /* 只写一个数表示水平方向 */
- transform: translate(100px);
-
- transform: translateY(100px);
- transform: translateX(100px);
- }
-
- </style>
- </head>
-
- <body>
- <div class="father">
- <div class="son"></div>
- </div>
- </body>
复制代码
- <title>绝对定位元素居中效果</title>
- <style>
- .box {
- position: absolute;
- left: 50%;
- top: 50%;
-
- /* 向左向上移动自身尺寸的一半 */
- transform: translate(-50%, -50%);
-
- width: 200px;
- height: 100px;
- background-color: pink;
- }
- </style>
- </head>
- <body>
- <div class="box"></div>
- </body>
复制代码
- <title>双开门</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- /* 1. 布局:父子结构,父级是大图,子级是左右小图 */
- .father {
- display: flex;
- margin: 0 auto;
- width: 1366px;
- height: 600px;
- background-image: url(./images/bg.jpg);
-
- overflow: hidden;
- }
-
- .father .left,
- .father .right {
- width: 50%;
- height: 600px;
- background-image: url(./images/fm.jpg);
-
- transition: all .5s;
- }
-
- .father .right {
- /* right 表示的取到精灵图右面的图片 */
- background-position: right 0;
- }
-
- /* 2. 鼠标悬停的效果:左右移动 */
- .father:hover .left {
- transform: translate(-100%);
- }
-
- .father:hover .right {
- transform: translateX(100%);
- }
- </style>
- </head>
-
- <body>
- <div class="father">
- <div class="left"></div>
- <div class="right"></div>
- </div>
- </body>
复制代码
|