八、变形

八、变形

8.1 2D变形

transform: 变形

8.1.1 旋转:rotate()

旋转:rotate()

单位是deg

正方向:顺时针

1
2
3
4
5
6
7
.box {
width: 200px;
border: 1px solid #000;
}
.box img {
width: 100%;
}

NUzZmd.png

img是行内元素,需要转块

1
display: block;

NUzc7R.png

1
2
3
.box:hover img {
transform:rotate(30deg); /*顺时针旋转30°*/
}

NaS45q.png

8.1.2 放缩 scale(数字)

scale(数字)

没有单位

0-1表示缩小

1-无穷 表示放大

1
2
3
4
/* 父盒子 溢出隐藏 */
overflow: hidden;

transform: scale(1.2);

NaptJ0.png

8.1.3 水平、垂直斜切 skew()

skew()

单位:deg

1
transform:skew(10deg,40deg);

NapDeJ.png

8.1.4 2D变形综合

同一个元素可以有多个变形,用空格隔开。

元素没有变形 none

1
transform:rotate(90deg) scale(1.2) skew(30deg,45deg);

NapWQO.png

8.2 2D空间移动

空间移动:

transform:translateX()表示水平方向移动(表示相对于自身当前位置进行偏移)

transform:translateY()表示垂直方向移动

transform:translate( 水平方向,垂直方向 )

单位:px

1
2
3
transform:translateX(10px); 
transform:translateY(10px);
transform:translate(10px,10px);

NapbfP.png

绝对定位的水平居中:

left:50%;

margin-left:-自身宽度/2 (可以用空间移动来实现)

1
2
3
/*子绝父相*/
left:50%;
transform: translateX(-50%);

NapX6S.png

8.3 练习

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
 <div class="box">
<ul>
<li><a href="">我要约考</a></li>
<li class="no2"><a href="">班型介绍</a></li>
<li class="no3"><a href="">班车服务</a></li>
<li class="no4"><a href="">在线法培</a></li>
<li class="no5"><a href="">网上约车</a></li>
</ul>
</div>


<style>
/* 清除默认样式 */
* {
padding: 0;
margin: 0;
}
a {
text-decoration: none;
color: #fff;
}
ul, ol {
list-style: none;
}
body {
font-family: "Arial", "Microsoft Yahei";
font-size: 14px;
}
.box {
width: 700px;
padding: 20px;
border: 1px solid #000;
background-color: rgba(0,0,0,.2);
margin: 50px auto;
overflow: hidden;
}
.box ul li {
float: left;
width: 107px;
height: 107px;
/* 同级元素有距离margin */
margin-right: 20px;
position: relative;
}
.box ul li::after {
content: "";
position: absolute;
height: 107px;
width: 107px;
background-image: url(images/a_1.png);
top: 0;
left: 0;
transition: all 1s linear 0s;
}
.box ul li.no2::after {
background-image: url(images/a_2.png);
}
.box ul li.no3::after {
background-image: url(images/a_3.png);
}
.box ul li.no4::after {
background-image: url(images/a_4.png);
}
.box ul li.no5::after {
background-image: url(images/a_5.png);
}
.box ul li::before {
content: "";
position: absolute;
width: 46px;
height: 42px;
background-image: url(images/tb_1.png);
left: 50%;
top: 20px;
transform: translateX(-50%);
/* 自定义压盖顺序 */
z-index: 4;
}
.box ul li.no2::before {
background-image: url(images/tb_2.png);
width: 40px;
}
.box ul li.no3::before {
background-image: url(images/tb_3.png);
width: 34px;
}
.box ul li.no4::before {
background-image: url(images/tb_4.png);
width: 41px;
}
.box ul li.no5::before {
background-image: url(images/tb_5.png);
width: 44px;
}
.box ul li a {
display: block;
width: 100%;
height: 100%;
/* line-hight 数值大于盒子高度 偏下显示 */
line-height: 150px;
text-align: center;
/* 有定位的元素压盖没有定位的元素
有定位的元素才可以设置z-index
*/
position: relative;
z-index: 10;
}
.box ul li:hover::after {
background-image: url(images/a_1_h1.png);
transform: rotate(360deg);
}
.box ul li.no2:hover::after {
background-image: url(images/a_2_h1.png);
}
.box ul li.no3:hover::after {
background-image: url(images/a_3_h1.png);
}
.box ul li.no4:hover::after {
background-image: url(images/a_4_h1.png);
}
.box ul li.no5:hover::after {
background-image: url(images/a_5_h1.png);
}
</style>

Na9FpV.png

点击查看

本文标题:八、变形

文章作者:Mango

发布时间:2020年06月30日 - 21:31:40

最后更新:2020年06月30日 - 21:44:19

原始链接:https://mango185.github.io/post/495d679d.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------