当前位置:网站首页>移动端实现0.5px的实用方案
移动端实现0.5px的实用方案
2022-07-24 18:08:00 【无围之解】
我们知道,理论上px的最小单位是1,但在设置px值时,直接设置0.5px不同浏览器的差异比较大,并且我们看到不同系统的不同浏览器对小数点的px有不同的处理。Chrome会把0.5px四舍五入变成了1px,把小于0.5px的当成0,Firefox会把不小于0.55px当成1px,Safari是把不小于0.75px当成1px。所以以下就总结了实现0.5px的实现方式。
方案1: 伪元素+scale (兼容性最好,推荐)
实现方式:给容器设置伪元素,设置绝对定位,宽高都是200%,边框是1px,然后使用transform:scale(0.5) 让伪元素缩小原来的一半,此时伪元素的边框和容器的边缘重合。
方案2: 伪元素+背景 (适合设置一条边框,没办法展示圆角)
实现方式:给容器设置伪元素,设置绝对定位,高度1px,背景图设置线性渐变,一半有颜色一半透明,视觉上只有0.5px。
方案3: 利用阴影代替边框
特点:方便,能正常展示圆角,而且能实现0.1px等更细的边框,兼容性还行。
代码实现
<style>
.box {
width: 360px;
height: 50px;
border-radius: 5px;
margin-top: 20px;
line-height: 50px;
}
/* 直接设置border-width */
.box-normal {
border: 0.5px solid red;
}
/* 方案1:伪元素+scale */
.box1 {
position: relative;
}
.box1::after {
position: absolute;
bottom: 0;
z-index: -边栏推荐
- 700. Search DFS method in binary search tree
- Has polardb for PostgreSQL entered the list of Xinchuang database?
- Common methods of number and math classes
- Review and analysis of noodle dishes
- 头文件是必须的吗?跟一跟编译过程~~~
- Shengxin commonly used analysis graphics drawing 02 -- unlock the essence of volcano map!
- ShardingSphere数据库读写分离
- SV强制类型转换和常数
- Handwritten blog platform ~ the next day
- 面会菜评论分析
猜你喜欢

Pay close attention! List of the latest agenda of 2022 open atom open source Summit

Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research

Tensorflow introductory tutorial (37) -- DC Vnet

Trends of semiconductor industry

Handwritten blog platform ~ the next day

Detailed explanation of ansible automatic operation and maintenance (V) the setting and use of variables in ansible, the use of jinja2 template and the encryption control of ansible

C language custom type explanation - structure

C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix

Tensorflow introductory tutorial (38) -- V2 net

Win10 super good-looking mouse theme, you also try it
随机推荐
0621~ES&Lucene
0629~SaaS平台设计~全局异常处理
After separation, the impression notes are still difficult to live, but there are many coquettish operations
运维小白成长记——架构第8周
Bib | mol2context vec: context aware deep network model learning molecular representation for drug discovery
ROC and AUC details of the recommended system
还在从零开始搭建项目?这款升级版快速开发脚手架值得一试!
快速完成intelij idea的单元测试JUnit4设置
The solution of single chip microcomputer not supporting printf floating point type
0615 ~ realize RBAC permission management with user-defined annotations
Laravel笔记-用户登录时密码进行RSA加密(提高系统安全性)
Emerging potential of interactive virtual reality technology in drug discovery
[network security] analysis vulnerability of website Middleware
Tensorflow introductory tutorial (37) -- DC Vnet
1688/ Alibaba searches new product data by keyword API instructions
Mozilla foundation released 2022 Internet health report: AI will contribute 15.7 trillion yuan to the global economy in 2030, and the investment in AI in the United States last year was nearly three t
继承与派生
Still building projects from scratch? This upgraded rapid development scaffold is worth a try!
C language custom types - Enumeration
Blackmagic Fusion Studio 18