通过创建猫咪绘画学习中级 CSS

哈基米还挺可爱的

效果

来自于freecodecamp

源码

index.html

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>fCC Cat Painting</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<main>
<div class="cat-head">
<div class="cat-ears">
<div class="cat-left-ear">
<div class="cat-left-inner-ear"></div>
</div>
<div class="cat-right-ear">
<div class="cat-right-inner-ear"></div>
</div>
</div>

<div class="cat-eyes">
<div class="cat-left-eye">
<div class="cat-left-inner-eye"></div>
</div>
<div class="cat-right-eye">
<div class="cat-right-inner-eye"></div>
</div>
</div>

<div class="cat-nose"></div>

<div class="cat-mouth">
<div class="cat-mouth-line-left"></div>
<div class="cat-mouth-line-right"></div>
</div>

<div class="cat-whiskers">
<div class="cat-whiskers-left">
<div class="cat-whisker-left-top"></div>
<div class="cat-whisker-left-middle"></div>
<div class="cat-whisker-left-bottom"></div>
</div>
<div class="cat-whiskers-right">
<div class="cat-whisker-right-top"></div>
<div class="cat-whisker-right-middle"></div>
<div class="cat-whisker-right-bottom"></div>
</div>
</div>

</div>
</main>
</body>
</html>

styles.css

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
* {
box-sizing: border-box;
}

body {
background-color: #c9d2fc;
}

.cat-head {
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 0;
margin: auto;
background: linear-gradient(#5e5e5e 85%, #45454f 100%);
width: 205px;
height: 180px;
border: 1px solid #000;
border-radius: 46%;
}

.cat-left-ear {
position: absolute;
top: -26px;
left: -31px;
z-index: 1;
border-top-left-radius: 90px;
border-top-right-radius: 10px;
transform: rotate(-45deg);
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 70px solid #5e5e5e;
}

.cat-right-ear {
position: absolute;
top: -26px;
left: 163px;
z-index: 1;
transform: rotate(45deg);
border-top-left-radius: 90px;
border-top-right-radius: 10px;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 70px solid #5e5e5e;
}

.cat-left-inner-ear {
position: absolute;
top: 22px;
left: -20px;
border-top-left-radius: 90px;
border-top-right-radius: 10px;
border-bottom-right-radius: 40%;
border-bottom-left-radius: 40%;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 40px solid #3b3b4f;
}

.cat-right-inner-ear {
position: absolute;
top: 22px;
left: -20px;
border-top-left-radius: 90px;
border-top-right-radius: 10px;
border-bottom-right-radius: 40%;
border-bottom-left-radius: 40%;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 40px solid #3b3b4f;
}

.cat-left-eye {
position: absolute;
top: 54px;
left: 39px;
border-radius: 60%;
transform: rotate(25deg);
width: 30px;
height: 40px;
background-color: #000;
}

.cat-right-eye {
position: absolute;
top: 54px;
left: 134px;
border-radius: 60%;
transform: rotate(-25deg);
width: 30px;
height: 40px;
background-color: #000;
}

.cat-left-inner-eye {
position: absolute;
top: 8px;
left: 2px;
width: 10px;
height: 20px;
transform: rotate(10deg);
background-color: #fff;
border-radius: 60%;
}

.cat-right-inner-eye {
position: absolute;
top: 8px;
left: 18px;
transform: rotate(-5deg);
width: 10px;
height: 20px;
background-color: #fff;
border-radius: 60%;
}

.cat-nose {
position: absolute;
top: 108px;
left: 85px;
border-top-left-radius: 50%;
border-bottom-right-radius: 50%;
border-bottom-left-radius: 50%;
transform: rotate(180deg);
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-bottom: 20px solid #442c2c;
}

.cat-mouth div {
width: 30px;
height: 50px;
border: 2px solid #000;
border-radius: 190%/190px 150px 0 0;
border-color: black transparent transparent transparent;
}

.cat-mouth-line-left {
position: absolute;
top: 88px;
left: 74px;
transform: rotate(170deg);
}

.cat-mouth-line-right {
position: absolute;
top: 88px;
left: 91px;
transform: rotate(165deg);
}

.cat-whiskers-left div {
width: 40px;
height: 1px;
background-color: #000;
}

.cat-whiskers-right div {
width: 40px;
height: 1px;
background-color: #000;
}

.cat-whisker-left-top {
position: absolute;
top: 120px;
left: 52px;
transform: rotate(10deg);
}

.cat-whisker-left-middle {
position: absolute;
top: 127px;
left: 52px;
transform: rotate(3deg);
}

.cat-whisker-left-bottom {
position: absolute;
top: 134px;
left: 52px;
transform: rotate(-3deg);
}

.cat-whisker-right-top {
position: absolute;
top: 120px;
left: 109px;
transform: rotate(-10deg);
}

.cat-whisker-right-middle {
position: absolute;
top: 127px;
left: 109px;
transform: rotate(-3deg);
}

.cat-whisker-right-bottom {
position: absolute;
top: 134px;
left: 109px;
transform:rotate(3deg);
}