-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path媒体查询正方形.html
134 lines (116 loc) · 2.51 KB
/
媒体查询正方形.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>媒体查询正方形</title>
<style>
.box {
display: flex;
}
.box div {
margin: 10px;
}
@media (min-width: 300px) and (max-width: 768px) {
.box1 {
position: relative;
background-color: red;
width: 40vw;
height: 40vw;
z-index: -3;
}
.box1:before {
content: "";
background-color: blue;
display: block;
width: 20vw;
height: 20vw;
z-index: -1;
}
.box1::after {
position: absolute;
top: 0;
left: 0;
content: "";
background-color: green;
display: block;
width: 30vw;
height: 30vw;
z-index: -2;
}
}
@media (min-width: 769px) and (max-width: 1080px) {
.box1 {
position: relative;
background-color: red;
width: 40vw;
height: 40vw;
z-index: -3;
}
.box1:before {
position: absolute;
content: "";
background-color: blue;
display: block;
width: 20vw;
height: 20vw;
z-index: -1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.box1::after {
position: absolute;
top: 0;
left: 0;
content: "";
background-color: green;
display: block;
width: 30vw;
height: 30vw;
z-index: -2;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
@media (min-width: 1081px) {
.box1 {
position: relative;
background-color: red;
width: 40vw;
height: 40vw;
z-index: -3;
}
.box1:before {
position: absolute;
content: "";
background-color: blue;
display: block;
width: 20vw;
height: 20vw;
z-index: -1;
right: 0;
bottom: 0;
}
.box1:after {
position: absolute;
content: "";
background-color: green;
display: block;
width: 30vw;
height: 30vw;
z-index: -2;
right: 0;
bottom: 0;
}
}
</style>
</head>
<body>
一、3个正方形盒子每个盒子各有1px外边距 颜色大小自定义,盒子尺寸跟随窗口大小变化实现效果如下
<div class="box">
<div class="box1"></div>
</div>
</body>
</html>