移动端一像素问题

时间:2017-09-04 11:36:00   收藏:0   阅读:299

最近我发现移动端中的一像素会有bug,为什么呢?我发现在测试时候,不同大小的手机一像素的边框会随屏幕变化。虽然不是很大的问题,但我发现面试的时候也会问,所以我就查找了一些回答来总结一下。

  1. 可以用缩小放大transform中的scale来实现:
    .border-bottom{
        position: relative;
        border-top: none !important;
    }
    
    .border-bottom::after {
        content: " ";
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 1px;
        background-color: #e4e4e4;
        -webkit-transform-origin: left bottom;
        transform-origin: left bottom;
    }

    然后通过媒体查询

    /* 2倍屏 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2.0) {
        .border-bottom::after {
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }
    }
    
    /* 3倍屏 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3.0) {
        .border-bottom::after {
            -webkit-transform: scaleY(0.33);
            transform: scaleY(0.33);
        }
    }

    其实是一像素的高度的块级元素。

  2. 第二种的方法很简单,就用一像素的图片来替代。
    .border-image-1px {
        border-width: 1px 0px;
        -webkit-border-image: url("##") 2 0 stretch;
    }

     

原文:http://www.cnblogs.com/weiyf/p/7472573.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!