实现.5px的线条

网络上有很多方法,如设置viewport,box-shawdow,border-image,background-image,transform:scale等,这里不做介绍(百度或者谷歌“retina 1px 边框”有答案),本文只介绍一种觉得比较好用的方法,一来兼容性好,二来不依赖图片。

transform:scale(x,y)

通过css支持定义border或者height为.5px大的线条,在android设备中的无法显示出来,这里有个小技巧,果设置线条为1px,然后通过transform:scale(x,y)来缩放线条为原来的一半,可显示0.5px的线条。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>点5测试 - scale</title>
<style type="text/css">
.line {
height: 50px;
line-height: 50px;
background-color: #CCC;
border-bottom:1px solid red
} .scale {
position: relative;
height: 50px;
line-height: 50px;
background-color: #CCC
}
.scale:after {
position: absolute;
content: '';
width: 100%;
left: 0;
bottom: 0;
height: 1px;
background-color: red;
-webkit-transform: scale(1,.5);
transform: scale(1,.5);
-webkit-transform-origin: center bottom;
transform-origin: center bottom
}
</style>
</head> <body>
<div class="line">1px</div>
<br/><br/>
<div class="scale">0.5px</div>
</body> </html>

http://peunzhang.github.io/demo/d5px/height-scale.html

实现.5px的圆角边框

.5px的边框,看起来看神奇,这里感谢蓝叔提供的方法。

原理:先定义1px的圆角边框,然后拉伸内容的宽度和高度为父级的2倍(边框厚度不变),然后再使用transform:scale(0.5)缩放为原来的0.5倍

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>点5测试 - border-radius</title>
<style type="text/css">
body{padding: 50px;-webkit-touch-callout:none;}
[class*="btn"]{margin: 0 auto;}
.btn-1 {
width: 200px;
height: 42px;
-webkit-border-radius: 5px;
border-radius: 5px;
text-align: center;
line-height: 42px;
background-color: #EDEDED;
border: 1px solid red;
}
.btn {
position: relative;
width: 200px;
height: 42px;
-webkit-border-radius: 5px;
border-radius: 5px;
text-align: center;
line-height: 42px;
background-color: #EDEDED;
}
.btn:before {
content: '';
position: absolute;
top: -50%;
bottom: -50%;
left: -50%;
right: -50%;
-webkit-transform: scale(0.5);
transform: scale(0.5);
border-style: solid;
border-width: 1px;
border-color: red;
-webkit-border-radius: 10px;
border-radius: 10px;
}
</style>
</script>
</head> <body> <div class="btn-1">1px border</div>
<br/><br/>
<div class="btn">.5px border</div> </body> </html>

http://1.peunzhang.sinaapp.com/demo/d5px/border-radius.html

如果你在chrome打开,会发现缩放线条会导致边框颜色变浅,但大家可以放心使用,因为在大部分移动设备(相对高端)的颜色还是正常的。

最新文章

  1. iOS NSUserDefaults 存放位置
  2. dp跟px的互相转换
  3. 【上手centos】一、前情以及sublime_text_3安装
  4. C++多态性——函数的覆盖和隐藏
  5. Python 读写文件和file对象(转)
  6. bzoj 1005 HNOI2008 明明的烦恼
  7. bzoj1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
  8. Hyper-V虚机跨NUMA节点性能影响
  9. SVN权限修复
  10. Ubuntu tty中文字符乱码
  11. SPARK 学习笔记一
  12. django restful 1-在线Python编辑器
  13. Linux 环境下umount, 报 device is busy 的问题分析与解决方法
  14. Oracle语言环境变量配置
  15. 爬取伯乐在线文章(四)将爬取结果保存到MySQL
  16. Linux的rp_filter与策略路由
  17. C# 移除Response Header,403调整返回为404Make IIS return a 404 status code instead of 403
  18. asp.net core web项目目录解读
  19. CSS全局居中
  20. Oracle调整内存超出限制出现ORA-27100: shared memory realm already exists问题解决办法

热门文章

  1. python基础(3):输入输出与运算符
  2. linux centos7 安装redis
  3. 使用curl模拟ip和来源进行网站采集的实现方法
  4. flume 1.7在windows下的安装与测试
  5. poj_3258:River Hopscotch(二分)
  6. xdu_1077:循环节长度
  7. PXE+Kickstart无人值守安装操作系统
  8. Java集合类小结-思维导图
  9. Java使用拦截器的两种方式
  10. (转)Java并发编程:Callable、Future和FutureTask