美文网首页
关于1px的实现

关于1px的实现

作者: 月下吴刚_c8c7 | 来源:发表于2018-12-24 13:20 被阅读0次

移动端页面宽度

  -   设置了initial-scale, 则页面布局宽度 = 设备逻辑像素宽度 * 像素比dpr, 也等于 设备逻辑像素宽度 (device-width) /  initial-scale;
      然后再缩放initial-scale, 达到与设备同宽,但布局宽度不变; 
  -   设置了width则宽度等于width的值;同时设置了initial-scale和width则宽度取两者中较大的一个。

1px的实现

https://www.cnblogs.com/lunarorbitx/p/5287309.html\

0.5px解决方案 ------- 安卓和iOS7之前版本碰到0.5px直接就解析成0px了,大多数安卓机兼容性有问题, 此法不能用 ;

box-shadow ------ 这个颜色不好弄,所以效果也不是很好。

border-image ------  代码挺简单,但是要自己制作图片,而且圆角也不好弄,如果改了颜色就要对图片处理,所以不是很好的方案。

多背景渐变实现 ---------- 与border-image类似, 只是将图片替换为css3渐变。设置1px的渐变背景,50%有颜色,50%透明. 兼容性较好

transform: scale(0.5)  ------ WeUI正在用的; :before, :after与transform,  之前说的frozenUI的圆角边框就是采用这种方式, 
构建1个伪元素, 将它的长宽放大到2倍, 边框宽度设置为1px, 再以transform缩放到50%.

viewport+rem实现:  --------- 利用像素比dpr 和 initial-scale , 将页面宽度设为 逻辑宽度 * dpr , 页面上的1px再缩放 initial-scale ,
就能得到标准的物理 1px,  此方法对安卓兼容不是太好;

flexible.js -----  px和rem相互转换的计算方法会暴露在window.lib.flexible中. 这样可以为less/sass编写宏方法. 具体的css改写方法
参照大 漠的文章
实际项目中特别指出了为了防止字体模糊, 出现奇数字号的字体, 字体的实际单位还是要以px为单位
缺点: 不适用安卓, flexible内部做了检测 非iOS机型还是采用传统的scale=1.0, 原因在于安卓手机不一定有devicePixelRatio属性, 
就算有也不一定能响应scale小于1的viewport缩放设置, 例如我的手机设置了scale=0.33333333, 显示的结果也与scale=1无异.

背景渐变实现 1px

.background-gradient-1px {
  background:
    linear-gradient(#000, #000 100%, transparent 100%) left / 1px 100% no-repeat,
    linear-gradient(#000, #000 100%, transparent 100%) right / 1px 100% no-repeat,
    linear-gradient(#000,#000 100%, transparent 100%) top / 100% 1px no-repeat,
    linear-gradient(#000,#000 100%, transparent 100%) bottom / 100% 1px no-repeat}/* 或者 */.background-gradient-1px{
  background:
    -webkit-gradient(linear, left top, right bottom, color-stop(0, transparent), color-stop(0, #000), to(#000)) left / 1px 100% no-repeat,
    -webkit-gradient(linear, left top, right bottom, color-stop(0, transparent), color-stop(0, #000), to(#000)) right / 1px 100% no-repeat,
    -webkit-gradient(linear, left top, right bottom, color-stop(0, transparent), color-stop(0, #000), to(#000)) top / 100% 1px no-repeat,
    -webkit-gradient(linear, left top, right bottom, color-stop(0, transparent), color-stop(0, #000), to(#000)) bottom / 100% 1px no-repeat}

:before, :after与transform 实现 1px
需要注意<input type="button">是没有:before, :after伪元素的

.radius-border{
    position: relative;
}
@media screen and (-webkit-min-device-pixel-ratio: 2){
    .radius-border:before{
        content: "";
        pointer-events: none; /* 防止点击触发 */
        box-sizing: border-box;
        position: absolute;
        width: 200%;
        height: 200%;
        left: 0;
        top: 0;
        border-radius: 8px;
        border:1px solid #999;
        -webkit-transform(scale(0.5));
        -webkit-transform-origin: 0 0;
        transform(scale(0.5));
        transform-origin: 0 0;
    }
}

相关文章

  • 关于1px的实现

    移动端页面宽度 1px的实现 https://www.cnblogs.com/lunarorbitx/p/5287...

  • 常用css总结

    垂直居中 伪类 + transform 实现移动端 Retina 屏幕 1px 边框 flex常用布局盒结构 关于...

  • 1像素边框实现

    实现原理 1.先用伪类实现1px的边框 2.通过对屏幕密度的判断,进行缩放

  • 响应式设计

    1.1px问题 在retina显示屏中,1px像素实际对应2px像素,为了实现真正的1px粗细,我们需要使用0.5...

  • border-image 实现1px原理

    图片本人: round类型:(平铺) repeat类型:(重复) stretch类型:(拉伸) 实现1px 原理 ...

  • 一些css常用的css技巧

    移动端1px实现的方法 .border-1px{ position:relative; } .border-1px...

  • 移动端一像素边框

    如何实现在移动端中显示一像素的边框 实现方案一:0.5像素 标准边框语法div{ border: 1px sol...

  • 移动端实现1px

    在移动端网页开发中,ui设计稿的边框设为1px,用css实现出来,我们会发现有些机型显示的边框实际比1px粗一些,...

  • Retina屏幕1px的实现

    一些基本概念 viewport 视窗 在桌面浏览器中,viewport就是浏览器窗口的宽度高度。但在移动端设备上,...

  • 虚线加宽

    使用border: 1px dashed #2754a2;实现的虚线间距太短,太丑,拒绝使用! 使用image的r...

网友评论

      本文标题:关于1px的实现

      本文链接:https://www.haomeiwen.com/subject/eisakqtx.html