移动端1像素展示问题解决方案

针对移动端 视网膜屏幕 设置1px 实际显示为 2px 问题,解决方法

使用方法: @include border(top, #ddd);

// 1像素边框
// $position:[边框位置]top, bottom, left, right
// $color:[边框颜色]
// $radius:[圆角]
// 使用:@include border(top, #ddd); 或 @include border(full, #ddd, 2px);
// 注意:父元素需使用相对定位:position: relative;
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
@mixin border($position: full, $borderColor: #ddd, $radius: 0) {
    content: '';
    position: absolute;
    z-index: 1;
    pointer-events: none;
    background-color: $borderColor;
    @if $position == top {
        height: 1px;left: 0;right: 0;top: 0;
        @media only screen and (-webkit-min-device-pixel-ratio:2) {
            &{
                -webkit-transform: scaleY(0.5);
                -webkit-transform-origin: 50% 0%;
            }
        }
    }
    @if $position == bottom {
        height: 1px;left: 0;right: 0;bottom: 0;
        @media only screen and (-webkit-min-device-pixel-ratio:2) {
            &{
                -webkit-transform: scaleY(0.5);
                -webkit-transform-origin: 50% 100%;
            }
        }
    }
    @if $position == left {
        width: 1px;top: 0;bottom: 0;left: 0;
        @media only screen and (-webkit-min-device-pixel-ratio:2) {
            &{
                -webkit-transform: scaleX(0.5);
                -webkit-transform-origin: 0% 50%;
            }
        }
    }
    @if $position == right {
        width: 1px;top: 0;bottom: 0;right: 0;
        @media only screen and (-webkit-min-device-pixel-ratio:2) {
            &{
                -webkit-transform: scaleX(0.5);
                -webkit-transform-origin: 100% 50%;
            }
        }
    }
    @if $position == full {
        border: 1px solid #ddd;top: 0;bottom: 0;left: 0;right: 0;
        background: none;
        border-color: $borderColor;
        @if $radius != 0 {
            border-radius: $radius;
        }
        @media only screen and (-webkit-min-device-pixel-ratio:2) {
            &{
                right: -100%;
                bottom:-100%;
                -webkit-transform:scale(0.5);
                -webkit-transform-origin: 0% 0%;
                $radiusx2: null;
                @each $i in $radius {
                    $radiusx2: append($radiusx2, $i * 2);
                }
                @if $radius != 0 {
                    border-radius: $radiusx2;
                }
            }
        }
    }
}

  

posted @   前端小小瀚  阅读(161)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示