• 关于移动端一像素线的解决方案


    为什么会有一像素线这个问题

      因为移动端布局我们大家都知道根据不同的手机会有不同的dpr 例如 爱疯6plus就是3  爱疯6就是2 当我们定义1px的时候就会在不同手机里面显示不同的粗细长度,dpr为3的时候就是3px,dpr为2的时候就是2px,具体dpr是什么意思不知道的朋友可以去百度一下。所以这个时候我们就需要解决这个1px像素线的问题

    解决办法

      1、yo3框架的解决办法

        通过yarn add yo3  / npm install yo3 来载入 yo3模块   PS:https://www.npmjs.com/package/yo3 不懂的同学可以去看官方文档

        然后再需要的地方引入@include border(border-weight[border-color,boder-style,border-radio])就可以完美解决一像素线的问题    

        但是这样引入需要有解析sass的工具,如果不想用sass的同学可以看下面第二种办法

      2、stylus解决办法

        

    border($border-width = 1px, $border-color = #ccc, $border-style = solid, $radius = 0)
      // 为边框位置提供定位参考
      position: relative;
    
      if $border-width == null
        $border- 0;
    
      border-radius: $radius;
    
      &::after
        // 用以解决边框layer遮盖内容
        pointer-events: none;
        position: absolute;
        z-index: 999;
        top: 0;
        left: 0;
        // fix当元素宽度出现小数时,边框可能显示不全的问题
        // overflow: hidden;
        content: "020";
        border-color: $border-color;
        border-style: $border-style;
        border- $border-width;
        
        // 适配dpr进行缩放
        @media (max--moz-device-pixel-ratio: 1.49), (-webkit-max-device-pixel-ratio: 1.49), (max-device-pixel-ratio: 1.49), (max-resolution: 143dpi), (max-resolution: 1.49dppx)
           100%;
          height: 100%;
          if $radius != null {
            border-radius: $radius;
          }
        
        @media (min--moz-device-pixel-ratio: 1.5) and (max--moz-device-pixel-ratio: 2.49), (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 2.49),(min-device-pixel-ratio: 1.5) and (max-device-pixel-ratio: 2.49),(min-resolution: 144dpi) and (max-resolution: 239dpi),(min-resolution: 1.5dppx) and (max-resolution: 2.49dppx)
           200%;
          height: 200%;
          transform: scale(.5)
          if $radius != null {
            border-radius: $radius * 2;
          }
        
        @media (min--moz-device-pixel-ratio: 2.5), (-webkit-min-device-pixel-ratio: 2.5),(min-device-pixel-ratio: 2.5), (min-resolution: 240dpi),(min-resolution: 2.5dppx)
           300%;
          height: 300%;
          transform: scale(.33333)
          if $radius != null {
            border-radius: $radius * 3;
          }
    
        transform-origin: 0 0;
    

      原理其实都差不多就是通过判断设备的dpr然后来缩放对应的比例,这样就能达到在任何dpr下都能保持一像素线的问题。

  • 相关阅读:
    winfrom绘制渐变 / 调用浏览器访问指定地址
    解决sever 2008中tomcat的报错 init Failed to initialize end point associated with ProtocolHandler ["http-nio-80"]
    SizeGripStyle 枚举
    不安全代码只会在使用/unsafe 编译的情况下出现
    VS2017自定义代码片段, 实现快捷输入
    C#获取程序代码执行时长
    C#简单操作XML
    数据库基线检查工具DB_BASELINE
    SQLmap使用手册小结(二)
    SQLmap使用手册小结(一)
  • 原文地址:https://www.cnblogs.com/w0613/p/9898097.html
Copyright © 2020-2023  润新知