总结一下各种0.5px的线
在PC端用1px的边框线,看起来还好,但在手机端看起来就很难看了,而0.5px的分割线会有种精致的感觉。用普通写法border:solid 0.5px red;iPhone可以正常显示,android下几乎所有的浏览器都会把0.5识别为0,即无边框状态.
原理
原理就是给需要加边框的元素插入一个伪类,伪类采用绝对定位,然后对伪类添加1px边框,最后进行0.5倍缩放。transform的缩放和旋转默认都是按照元素的中心点来操作的
outline元素在缩放0.5之前尺寸就是红框元素,缩放后,位置到了红框中心,为了使之依然在左上角,缩放之前我们需进行left:-50%;top:-50%的位移。
0.5px边框
<div class="first">
  <div class="first-div">
    HELLO WORLD
  </div>
</div>
<style>
.first{
  position: relative;
  font-size: 16px;
}
.first .first-div:before{
  content: "";
  position: absolute;
  top: -50%;
  bottom: -50%;
  left: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  -webkit-transform: scale(0.5);
  transform: scale(0.5);
  border: solid 1px red;
  box-sizing:border-box;
}
</style>
副作用
当用伪类的绝对定位来实现了边框后,我们在first类和first-div类上的点击事件会失效,因为此时的伪类是绝对定位,而且长宽等于父类元素的长宽,是脱离了文档流覆盖在父类上的,伪类不是真实的DOM元素,没有js点击事件
- 解决方案
 
再写一个绝对定位元素,覆盖在父元素上,层级优先级要高一点
<div class="first">
  <div class="first-div">
    HELLO WORLD
  </div>
  <div class="click-able" onclick="alert('click')"></div>
</div>
<style>
.first{
  position: relative;
  font-size: 16px;
}
.first .first-div:before{
  content: "";
  position: absolute;
  top: -50%;
  bottom: -50%;
  left: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  -webkit-transform: scale(0.5);
  transform: scale(0.5);
  border: solid 1px red;
  box-sizing:border-box;
}
.click-able{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
}
  </style>
0.5px圆角边框
<div class="round">
  <div class="round-div">
    HELLO WORLD
  </div>
</div>
<style>
.round{
   position: relative;
   font-size: 16px;
 }
.round .round-div:before{
  content: "";
  position: absolute;
  top: -50%;
  bottom: -50%;
  left: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  -webkit-transform: scale(0.5);
  transform: scale(0.5);
  border: solid 1px red;
  border-radius: 22px;
  box-sizing:border-box;
}
</style>
0.5px左边线
<div class="left">
  <div class="left-div">
    HELLO WORLD
  </div>
</div>
<style>
.left{
  position: relative;
  font-size: 16px;
}
.left .left-div:before{
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 100%;
  border-left: 1px solid red;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: scaleX(0.5);
  transform: scaleX(0.5);
}
</style>
0.5px右边线
<div class="right">
  <div class="right-div">
    HELLO WORLD
  </div>
</div>
<style>
.right{
  position: relative;
  font-size: 16px;
  display: inline-block;
}
.right .right-div:before{
  content: " ";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 100%;
  border-right: 1px solid red;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: scaleX(0.5);
  transform: scaleX(0.5);
}
</style>
0.5px底部线
<div class="bottom">
  <div class="bottom-div">
    HELLO WORLD
  </div>
</div>
<style>
.bottom{
  position: relative;
  font-size: 16px;
}
.bottom .bottom-div:before{
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  border-top: 1px solid red;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: scaleY(0.5);
  transform: scaleY(0.5);
}
</style>
本文转载于:猿2048→https://www.mk2048.com/blog/blog.php?id=hcbka1jabaa
总结一下各种0.5px的线的更多相关文章
- CSS画0.5px的线
		
今天遇到一个需求,画0.5px的线,查了以下资料,主要以scale方法为主.代码如下: /*0.5px上边框*/ .half_top_border_before:before{ content: &q ...
 - 实现0.5px边框线
		
实现0.5px边框方法 方案一:利用渐变(原理:高度1px,背景渐变,一半有颜色,一半透明) CSS部分 .container { width: 500px; margin: 0px auto; } ...
 - 画一条0.5px的线
		
通过伪类元素:after为其添加样式,用transform:scaleY令其在垂直方向缩小0.5倍 .div:after{ height: 1px; transform: scaleY(0.5); t ...
 - css3写出0.5px的边框
		
一说到0.5px的边框,我们一般认为是不行的,因为在ps中0.5px的线也是做不出来的,这个计算机的像素有关系. 废话不多说了,0.5px 其实用的是css3新特性,box-shadow:阴影设置 代 ...
 - 移动端 Retina屏border实现0.5px
		
首先来看一下造成Retina边框变粗的原因 其实这个原因很简单,因为css中的1px并不等于移动设备的1px,这些由于不同的手机有不同的像素密度.在window对象中有一个devicePixelRat ...
 - CSS 0.5px 细线边框的原理和实现方式
		
细线边框的具体实现方法有:伪元素缩放或渐变,box-shadow模拟,svg画线,border-image裁剪等.要实现小于1px的线条,有个先决条件:屏幕的分辨率要足够高,设备像素比要大于1,即cs ...
 - CSS3实现0.5px的边框
		
前端页面细节处理好了才会显得精致.边框在网页中是常见的一种样式了.虽然不把它处理为0.5px看上去没毛病,但是想让你做的东西征服更多的人,这些细节处理是必须的. 今天主要说一下如何让边框显示0.5px ...
 - css 0.5px
		
1. 利用css3新属性scale(好用推荐) 其实现的关键就是利用before或after伪元素,宽高同时设为200%,然后再缩放0.5,自然就是0.5px了 代码如下: div { positon ...
 - 怎么画一条0.5px的边
		
编者按:本文由人人网FED发表于掘金,并已授权奇舞周刊转载 什么是像素? 像素是屏幕显示最小的单位,在一个1080p的屏幕上,它的像素数量是1920 1080,即横边有1920个像素,而竖边为1080 ...
 
随机推荐
- Qt:QListWidget
			
0.说明 QListWidget指明一个基于Item的List Widget. 构造 QListWidget与QListView类似,都可以显示一列Item,区别在于前者可以往其中增删Item. QL ...
 - Excel:如何在间断的序号间插入空行
			
https://jingyan.baidu.com/article/e6c8503cb7ad7de54e1a1851.html
 - linux文本编辑工具
			
文本编辑工具VIM vim 主要有三种工作模式,分别是命令模式.插入模式和编辑模式,输入 vim 文件名 我们可以进入命令模式,输入字符 i或者a或者o我们可以进入插入模式,进入插入模式之后我们可以进 ...
 - Spring Session原理解析
			
前景提要: @EnableRedisHttpSession导入RedisHttpSessionConfiguration.classⅠ.被RedisHttpSessionConfiguration继承 ...
 - 10 分钟讲完 QUIC 协议。
			
建议阅读本文需要搭配作者 HTTP 相关文章食用. 历史 HTTP 系列文章: 看完这篇HTTP,跟面试官扯皮就没问题了 HTTP 2.0 ,有点炸 ! 这里先来回顾一下 HTTP 的发展过程.首先, ...
 - springWeb——Servlet
			
6.1.Servlet简介 servlet是sun公司开发动态web的一门技术 sum在这些API中提供了一个接口叫做:Servlet.开发的两个步骤: 编写一个类,实现Servlet接口 把开发好的 ...
 - 嵌入式Linux应用开发完全手册之环境搭建
			
@ 目录 0.下载源配置 1.电脑BIOS启动虚拟化 2.linux网卡查看与IP设置 3.windows NAT虚拟网络配置 4.修改 Ubuntu 的 mountd 端口 5.vim设置 6.Mo ...
 - knife4j只用此插件的最简洁开发方式
			
一.POM添加 在pom文件里添加包 1 <!--引入knife4j以来--> 2 <dependency> 3 <groupId>com.github.xiaoy ...
 - Visual Studio 2022 预览版下载来了(x64位)
			
Visual Studio 2022 预览版下载:https://visualstudio.microsoft.com/zh-hans/vs/preview/vs2022/
 - matplotlib字体
			
matplotlib官方文档 https://matplotlib.org/stable/gallery/index.html 使用以下代码查看 import matplotlib.pyplot as ...