移动端一像素边框

这里使用的是 scssmixin

/* 1像素边框 */

@mixin border($width: 1px, $border-color: $color-border, $border-radius: initial) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        border: $width solid $border-color;
        border-radius: $border-radius;
        box-sizing: border-box;
        width: 100%;
        height: 100%;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            width: 200%;
            height: 200%;
            transform: scale(0.5);
            transform-origin: left top;
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            width: 300%;
            height: 300%;
            transform: scale(0.333333);
            transform-origin: left top;
        }
    }
}

@mixin border-bottom($height: 1px, $width: 100%, $border-color: $color-border) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            background-color: $border-color;
            transform: scaleY(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            background-color: $border-color;
            transform: scaleY(0.333333);
        }
    }
}

@mixin border-top($height: 1px, $width: 100%, $border-color: $color-border) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            transform: scaleY(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            transform: scaleY(0.333333);
        }
    }
}

@mixin border-right($height: 100%, $width: 1px, $border-color: $color-border) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            transform: scaleX(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            transform: scaleX(0.333333);
        }
    }
}

@mixin border-left($height: 100%, $width: 1px, $border-color: $color-border) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            transform: scaleX(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            transform: scaleX(0.333333);
        }
    }
}
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
上次更新: 4/23/2019, 11:52:30 AM