使用于所有手机的0.5px的border

1px的线在手机上会影响美感,太粗,这个时候,需要兼容所有手机的0.5px的线。iphone手机支持.5px的设置,字体方面也是支持任何大小的字体。而安卓手机不支持.5px的设置,浏览器会渲染为1px。在字体方面,安卓手机最小支持8px的字体设置,如果设置的再小点,还是显示为8px的大小。(Webkit内核的适用范围较为广泛,Android原生浏览器、苹果的Safari、谷歌的Chrome(Android4.0使用)都是基于Webkit开源内核开发的。)

下面介绍兼容各种浏览器的物理像素为1px的实现方式:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>物理高度为1px的border</title>
    <meta name="viewport" content="width=device-width, maximum-scale=1, minimum-scale=1"/>
    <style type="text/css">
@media (-webkit-min-device-pixel-ratio: 2) {
    .border,.border-top,.border-right, .border-bottom, .border-left, .border-horizontal {
        position: relative;
        z-index: 1;
        border-width: 0;
    }
    .border:after, .border-top:after, .border-right:after, .border-bottom:after, .border-left:after, .border-horizontal:after{
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        z-index: -1;
        box-sizing: border-box;
        width: 200%;
        height: 200%;
        border-radius: 70px;
        transform: scale(.5);
        transform-origin: 0 0;
        pointer-events: none;
    }
    .border:after {
        border: 1px solid #e7e7e7;
    }
    .border-top:after {
        border-top: 1px solid #e7e7e7;
        height: 1px;
    }
    .border-right:after {
        left: auto;
        right: 0;
        width: 1px;
        border-right: 1px solid #e7e7e7;
    }
    .border-bottom:after {
        top: auto;
        bottom: 0;
        height: 1px;
        border-bottom: 1px solid #e7e7e7;
    }
    .border-left:after {
        width: 1px;
        border-left: 1px solid #e7e7e7;
    }
    .border-horizontal:after {
        border-top: 1px solid #e7e7e7;
        border-bottom: 1px solid #e7e7e7;
    }
    .border-vertical:after {
        border-left: 1px solid #e7e7e7;
        border-right: 1px solid #e7e7e7;
    }
}
.test {
    height: 200px;
}
</style>
</head>
<body>
    <div class="border-horizontal test"></div>
</body>
</html>

结果:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值