在移动端中如何绘制0.5px像素

  • 基本定义

    ​ 设计师在做设计图的时候都是以iphone6(宽为750物理像素)为基准进行设计的。iphone6的设备像素比(即css像素与物理像素的比例)是2,所以设计师在设计图画了边框为1px的box的时候,相对于css代码来说就是0.5像素。如果用css直接设置边框为0.5px,这种情况下iPhone可以正常显示,但是android下几乎所有的浏览器都会把0.5识别为0,即无边框状态,所以这种方式行不通的

  • 代码实现

    <!DOCTYPE html>
    <html>
    <head>
     <meta charset="utf-8">
     <title>0.5px线实现方法</title>
     <style type="text/css">
     /*标准1px边框*/
     .b1{
     height: 40px;
     border: 1px solid #ff0000;
     }
     /*1.可以利用利用渐变样式=>实现.5px*/
     .a1{
     height: 1px;
     margin-top: 20px;
     background-image: linear-gradient(0deg, #f00 50%, transparent 50%);
     }
     /*2.可以利用缩放-发虚=>实现.5px*/
     .a2{
     height: 1px;
     margin-top: 20px;
     background-color: #f00;
     -webkit-transform: scaleY(.5);
     transform:scaleY(.5);
     }
     /*3.四条边框都需要的样式*/
     .scale-half {
     margin-top: 20px;
     height: 100px;
     border:1px solid #f00;
     -webkit-transform-origin: 0 0;
     transform-origin: 0 0;
     -webkit-transform: scale(.5, .5);
     transform: scale(.5, .5);
     }
     /*4.给伪元素添加设置边框*/
     .border3{
     position: relative;
     }
     .border3:before{
     content: '';
     position: absolute;
     width: 200%;
     height: 200%;
     border: 1px solid blue;
     -webkit-transform-origin: 0 0;
     -moz-transform-origin: 0 0;
     -ms-transform-origin: 0 0;
     -o-transform-origin: 0 0;
     transform-origin: 0 0;
     -webkit-transform: scale(.5, .5);
     -ms-transform: scale(.5, .5);
     -o-transform: scale(.5, .5);
     transform: scale(.5, .5);
     -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
     box-sizing: border-box;
     }
     </style>
    </head>
    <body>
    <div class="b1">正常1px边框</div>
    <div class="a1"></div>
    <div class="a2"></div>
    <div class="scale-half"></div>
    <div class="border3">
     <div class="content">伪类设置的边框</div>
    </div>
    </body>
    </html>
    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值