其实在stylus与sass中实现移动端1像素线各个手机设备的适配问题的原理是一样的,

首先我还是先介绍一下原理和所依赖的方法

原理:其实他们都是通过css3的媒体查询来实现的

步骤思路:

1、给目标元素进行相对定位

2、给目标元素添加伪元素 ::after/before  并进行绝对定位

3、判断DPI   1DPI   100%   --------------使用媒体查询

2DPI   200%

3DPI   300%

4、通过css3中的transform scale等比缩放

下面是具体的代码,使用时只需引入代码  在style里直接写   border: 1px 0 0 0, #ccc   即可使用

在stylus中

border($border-width = 1px, $border-color = #ccc, $border-style = solid, $radius = )
// 为边框位置提供定位参考
position: relative; if $border-width == null
$border-width: ; border-radius: $radius; &::after
// 用以解决边框layer遮盖内容
pointer-events: none;
position: absolute;
z-index: ;
top: ;
left: ;
// fix当元素宽度出现小数时,边框可能显示不全的问题
// overflow: hidden;
content: "\0020";
border-color: $border-color;
border-style: $border-style;
border-width: $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: .49dppx)
width: %;
height: %;
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: .5dppx) and (max-resolution: .49dppx)
width: %;
height: %;
transform: scale(.)
if $radius != null {
border-radius: $radius * ;
} @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: .5dppx)
width: %;
height: %;
transform: scale(.)
if $radius != null {
border-radius: $radius * ;
} transform-origin: ;

在sass中

@mixin border($border-width: 1px, $border-color: map-get($base, border-color), $border-style: solid, $radius: null) {
// 为边框位置提供定位参考
position: relative;
@if $border-width == null {
$border-width: ;
}
border-radius: $radius;
&::after {
// 用以解决边框layer遮盖内容
pointer-events: none;
position: absolute;
z-index: ;
top: ;
left: ;
// fix当元素宽度出现小数时,边框可能显示不全的问题
// overflow: hidden;
content: "\0020";
border-color: $border-color;
border-style: $border-style;
border-width: $border-width;
// 适配dpr进行缩放
@include responsive(retina1x) {
width: %;
height: %;
@if $radius != null {
border-radius: $radius;
}
}
@include responsive(retina2x) {
width: %;
height: %;
@include transform(scale(.));
@if $radius != null {
border-radius: $radius * ;
}
}
@include responsive(retina3x) {
width: %;
height: %;
@include transform(scale(.));
@if $radius != null {
border-radius: $radius * ;
}
}
@include transform-origin( );
}
}

在component中

import styled from 'styled-components'

const border = ({
component = null,
width = '1px',
style = 'solid',
color = '#ccc',
radius = ,
}) => {
return styled(component) `
position: relative;
border-width: ${ width};
border-radius: ${ radius + 'px'};
&::after {
pointer-events: none;
position: absolute;
z-index: ;
top: ;
left: ;
content: "";
border-color: ${ color};
border-style: ${ style};
border-width: ${ width}; @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: .49dppx) {
width: %;
height: %;
border-radius: ${ radius + 'px'};
}; @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: .5dppx) and (max-resolution: .49dppx) {
width: %;
height: %;
transform: scale(.);
border-radius: ${ radius * + 'px'};
}; @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: .5dppx) {
width: %;
height: %;
transform: scale(.);
border-radius: ${ radius * + 'px'}
}; transform-origin: ;
};
`
} export default border

亲自使用过超级好使

如果本文对您有帮助,请抬抬您的小手,点下右下角的推荐, ^-^,当然如果看了这篇博客对您有帮助是我最开心的事,毕竟赠人玫瑰,手有余香, ^-^,如果这篇博客没有帮助到您,那就只能说一声抱歉啦

移动端1px线适配问题-------适配各种编译CSS工具 stylus sass styled-componet实现方法的更多相关文章

  1. CSS3 移动端 1PX 线变成0.5PX

    .line1 {position:relative} .line1:after {content:'';position:absolute;bottom:0;left:0;width:100%;hei ...

  2. 目前解决移动端1px边框最好的方法

    在移动端开发时,经常会遇到在视网膜屏幕中元素边框变粗的问题.本文将带你探讨边框变粗问题的产生原因及介绍目前市面上最好的解决方法. 1px 边框问题的由来 苹果 iPhone4 首次提出了 Retina ...

  3. 移动端1px细线解决方案总结

    现在的PM和UI总以看app的眼光看html5, html页面要做的专业美观,而且必须很精细. 去年的时候UI就告诉我h5上的边框线太粗,把整站都给拉low了. 当时工期紧就没太在意1px粗细, 好在 ...

  4. 移动端1px边框伪类宽高计算

    移动端1px边框在手机上看显得比较粗,于是我们用伪类结合css3缩放的方法去设置线条,但是如果设置div的一条边,水平线就设置宽度100%,垂直线就设置高度100%,那么如果是div的四条边呢?宽高1 ...

  5. 移动端1px边框

    问题:移动端1px边框,看起来总是2倍的边框大小,为了解决这个问题试用过很多方法,用图片,用js判断dpr等,都不太满意, 最后找到一个还算好用的方法:伪类 + transform 原理是把原先元素的 ...

  6. 老项目的#iPhone6与iPhone6Plus适配#LaunchImage适配

    本文永久地址为 http://www.cnblogs.com/ChenYilong/p/4020384.html,转载请注明出处.  Evernote印象笔记链接:https://www.everno ...

  7. 老项目的#iPhone6与iPhone6Plus适配#Icon适配

        本文永久地址为http://www.cnblogs.com/ChenYilong/p/4020373.html ,转载请注明出处.  这是Evernote印象笔记的链接:https://www ...

  8. 移动端1px问题处理方法

    在做移动端开发时,设计师提供的视觉稿一般是750px,当你定义 border-width:1px 时,在iphone6手机上却发现:边框变粗了.. 这是因为,1px是相对于750px的(物理像素),而 ...

  9. 移动端1px细线解决方案--利用transform缩放方式

    移动端1px会显示为2px; 解决方式很多,这里介绍比较常用的一种方式--css的transform属性缩放 1. 上边框 相当于 border-top <div class="bor ...

随机推荐

  1. YTU 2440: C++习题 复数类--重载运算符+,-,*,/

    2440: C++习题 复数类--重载运算符+,-,*,/ 时间限制: 1 Sec  内存限制: 128 MB 提交: 1189  解决: 774 题目描述 定义一个复数类Complex,重载运算符& ...

  2. jquery a

    <!DOCTYPE html><html><head><script src="//ajax.googleapis.com/ajax/libs/jq ...

  3. POJ - 2418 Hardwood Species(map,trie,BST)

    1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...

  4. 并不对劲的bzoj4825:loj2018:p3721:[HNOI2017]单旋

    题目大意 spaly是一种数据结构,它是只有单旋的splay 有一个初始为空的spaly,\(m\)(\(m\leq10^5\))次操作,每个操作是以下5种中的一种: 1.向spaly中插入一个数(过 ...

  5. 使用Visual Studio 利用WinGDB编译和远程调试嵌入式Linux的程序

    写这篇文章的目的在于帮助那些既要使用Visual Studio编写程序又要开发和调试嵌入式Linux 程序的苦命程序员们! 第一步, 安装 WinGDB ,下载位置  http://www.wingd ...

  6. ['1' for i in range(4)]

    ' for i in range(4)]) 结果: [']

  7. 设计模式-Template Method Pattern

    将generic部份放在abstract base class中的实现的方法中,而将和具体context相关的部份作为abstract base class的虚方法,由derivatives去实现. ...

  8. 11.2NOIP模拟赛

    /* 根右左遍历后最长上升子序列 */ #include<iostream> #include<cstdio> #include<cstring> #include ...

  9. python网络爬虫之四简单爬取豆瓣图书项目

    一.爬虫项目一: 豆瓣图书网站图书的爬取: import requests import re content = requests.get("https://book.douban.com ...

  10. 找规律 UVALive 6506 Padovan Sequence

    题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...