# 1px 线/边
背景知识: box-shadow (opens new window), transform (opens new window), @media (opens new window)
box-shadow
+transform
实现 1px 线条
<style scoped>
main {
width: 100%;
padding: 52px 29px;
display: flex;
justify-content: center;
}
span.one-pixel-line {
width: 229px;
position: relative;
}
span.one-pixel-line::after {
content: '';
width: 229px;
position: absolute;
bottom: 0;
left: 0;
box-shadow: 0 0 0 1px #b4a078;
transform-origin: 0 bottom;
transform: scaleY(.5) translateZ(0);
}
@media (min-resolution: 2dppx) {
span.one-pixel-line.shadow::after {
box-shadow: 0 0 0 .5px #b4a078;
}
}
@media (min-resolution: 3dppx) {
span.one-pixel-line.shadow::after {
box-shadow: 0 0 0 .333333px #b4a078;
}
}
.border-1px {
position: relative;
}
.border-1px:after {
position: absolute;
content: '';
top: -50%;
bottom: -50%;
left: -50%;
right: -50%;
-webkit-transform: scale(0.5);
transform: scale(0.5);
border-top: 1px solid #666;
border-bottom: 1px solid #666;
}
</style>
<template>
<main class="main">
<span class="one-pixel-line shadow"></span>
<div class="border-1px"></div>
</main>
</template>
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
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
border
+伪元素
+transform
实现 1px 独立边框
<style scoped>
main {
width: 100%;
padding: 52px 29px;
display: flex;
justify-content: center;
}
span.one-pixel-line {
display: block;
width: 229px; height: 229px;
position: relative;
}
span.one-pixel-line.right,
span.one-pixel-line.bottom,
span.one-pixel-line.left {
margin-left: -229px;
}
span.one-pixel-line::before,
span.one-pixel-line::after {
content: "";
display: block;
position: absolute;
transform-origin: 0 0;
}
/*top line*/
span.one-pixel-line.top::before {
width: 100%;
top: 0; left: 0;
border-top: 1px solid #b4a078;
transform-origin: 0 top;
}
@media (min-resolution: 2dppx) {
span.one-pixel-line.top::before {
width: 200%;
transform: scale(.5) translateZ(0);
}
}
@media (min-resolution: 3dppx) {
span.one-pixel-line.top::before {
width: 300%;
transform: scale(.333333) translateZ(0);
}
}
/*right line*/
span.one-pixel-line.right::after {
height: 100%;
top: 0; right: 0;
border-right: 1px solid #b4a078;
transform-origin: right 0;
}
@media (min-resolution: 2dppx) {
span.one-pixel-line.right::after {
height: 200%;
transform: scale(.5) translateZ(0);
}
}
@media (min-resolution: 3dppx) {
span.one-pixel-line.right::after {
height: 300%;
transform: scale(.333333) translateZ(0);
}
}
/*bottom line*/
span.one-pixel-line.bottom::after {
width: 100%;
bottom: 0; left: 0;
border-bottom: 1px solid #b4a078;
transform-origin: 0 bottom;
}
@media (min-resolution: 2dppx) {
span.one-pixel-line.bottom::after {
width: 200%;
transform: scale(.5) translateZ(0);
}
}
@media (min-resolution: 3dppx) {
span.one-pixel-line.bottom::after {
width: 300%;
transform: scale(.333333) translateZ(0);
}
}
/*left line*/
span.one-pixel-line.left::before {
height: 100%;
top: 0; left: 0;
border-left: 1px solid #b4a078;
transform-origin: 0 left;
}
@media (min-resolution: 2dppx) {
span.one-pixel-line.left::before {
height: 200%;
transform: scale(.5) translateZ(0);
}
}
@media (min-resolution: 3dppx) {
span.one-pixel-line.left::before {
height: 300%;
transform: scale(.333333) translateZ(0);
}
}
</style>
<template>
<main class="main">
<span class="one-pixel-line top"></span>
<span class="one-pixel-line right"></span>
<span class="one-pixel-line bottom"></span>
<span class="one-pixel-line left"></span>
</main>
</template>
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
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