半转的意思是借鉴参考,搬砖,加了一些自己的想法。

在移动端里,因为存在2倍像素的问题,所以很多时候,移动端上的1px边框并不是意义上的。从下图红色框看到dpr:2.0 ,表示1px等于2倍的物理像素。

网上找了一下,自己总结了一下。

实现方法代码如下:

 <!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>1px的边框问题</title>
<style type="text/css">
.line {
height: 50px;
width: 200px;
line-height: 50px;
background-color: #CCC;
text-align: center;
border-bottom:1px solid red;
margin-bottom: 20px;
} .scale {
height: 50px;
width: 200px;
line-height: 50px;
background-color: #CCC;
text-align: center;
margin-bottom: 20px;
}
.scaleV2 {
height: 50px;
width: 200px;
line-height: 50px;
text-align: center;
background-color: #CCC;
margin-bottom: 20px;
border-radius: 5px; }
.topLine,.bottomLine,.leftLine,.rightLine,.borderLine,.radiusLine{
position: relative;
}
.bottomLine:after {
position: absolute;
content: '';
width: 200%;
left: 0;
bottom: 0;
height: 1px;
padding-bottom: 1px;
background-color: red;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: left bottom;
transform-origin: left bottom;
}
.topLine:after {
position: absolute;
content: '';
width: 200%;
left: 0;
top: 0;
height: 1px;
background-color: red;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: left bottom;
transform-origin: left bottom;
}
.leftLine:after {
position: absolute;
content: '';
width: 1px;
left: 0;
top: 0;
height: 200%;
background-color: red;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: left bottom;
transform-origin: left top;
}
.rightLine:after {
position: absolute;
content: '';
width: 1px;
right: 0;
top: 0;
height: 200%;
background-color: red;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: center bottom;
transform-origin: right top;
} .borderLine:after {
position: absolute;
content: '';
width: 200%;
left: 0;
top: 0;
height: 200%;
border: 1px solid red;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: left top;
transform-origin: left top;
} .radiusLine:after {
position: absolute;
content: '';
width: 200%;
left: 0;
top: 0;
height: 200%;
border: 1px solid red;
border-radius: 10px;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: left top;
transform-origin: left top;
}
</style>
</head> <body>
<div class="line">1px</div>
<div class="scale topLine">0.5px 上边框</div>
<div class="scale bottomLine">0.5px 下边框</div>
<div class="scale leftLine">0.5px 左边框</div>
<div class="scale rightLine">0.5px 右边框</div>
<div class="scale borderLine">0.5px 边框</div>
<div class="scaleV2 radiusLine">0.5px 圆角边框</div>
</body> </html>

其实还是发现有一些的问题。

就是在在圆角的情况下会有写漏空。

看了一个大神的博客,他是用这样的一种方法的。没有这样的问题。

.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;
}

实现.5px的圆角边框

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

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

转:http://peunzhang.cnblogs.com/

[半转]1px边框 移动端的更多相关文章

  1. 移动端1px边框

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

  2. 移动端视网膜(Retina)屏幕下1px边框线 解决方案

    原因: 因为Retine屏的分辨率始终是普通屏幕的2倍,1px的边框在devicePixelRatio=2的retina屏下会显示成2px. 但在IOS8中,已经支持0.5px了,那就意味着, 在de ...

  3. 7种方法解决移动端Retina屏幕1px边框问题

    在Reina(视网膜)屏幕的手机上,使用CSS设置的1px的边框实际会比视觉稿粗很多.在之前的项目中,UI告诉我说我们移动项目中的边框全部都变粗了,UI把他的设计稿跟我的屏幕截图跟我看,居然真的不一样 ...

  4. 移动端1px边框实现

    问题描述:移动端iPhone上的1px边框看起来像2px那么粗.问题分析:不同的手机有不同的像素密度,在window对象中有一个devicePixelRatio属性,它可以反应设备的像素与css中的像 ...

  5. 7种方法实现移动端Retina屏幕1px边框效果

    在Reina(视网膜)屏幕的手机上,使用CSS设置的1px的边框实际会比视觉稿粗很多.在之前的项目中,UI告诉我说我们移动项目中的边框全部都变粗了,UI把他的设计稿跟我的屏幕截图跟我看,居然真的不一样 ...

  6. 移动端1px边框问题

    用于手机端受dpr的影响,实际开发中,PC端和移动端展示的效果不太一样,往往在PC端显示的是1px,移动端常常是偏粗一些. 解决办法: 主要是用到伪类及缩放.在需要画边框的元素上,设置一个伪类,它的伪 ...

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

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

  8. CSS3实现小于1px的边框(移动端)

    <!doctype html> <html lang="en"> <head> <meta content="width=dev ...

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

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

随机推荐

  1. C# Session添加、删除封装类

    /// <summary> /// <para> </para> /// 常用工具类——Session操作类 /// <para> ---------- ...

  2. jQuery动画与特效详解

    本文主要是讲解和学习jQuery的自动显隐,渐入渐出等. 1.显示和隐藏hide()和show() 对于动画来说,显示和隐藏是最基本的效果之一,本节简单介绍jQuery的显示和隐藏. 代码如下: &l ...

  3. 在SharePoint 2013 之中使用JS从Add-in程序中读取用户配置文件的属性

    经过无数次的实验,只有这个程序可以运行正常 ,代码贴出来纯的JSOM,在我的实验环境老是返回未知错误,为了这一个简单的任务,我已经搞了2天了,不过终于搞出来了,使用各种方法后,还有使用代码. func ...

  4. 学习笔记 MYSQL报错注入(count()、rand()、group by)

    首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...

  5. Android 绘制view的小知识点

    [onMeasure] 直接继承view或ViewGroup的自定义控件需要重写onMeasure方法并设置wrap_content时的自身大小,否则在布局中使用wrap_content就相当于mat ...

  6. 服务器开启https协议

    开启Tomcat https服务 发布企业级应用的时候遇到一个问题,就是IOS7.1之后app的下载地址URL必须是https开头的协议,所以服务器必须支持https协议. 实验环境:Mac OSX ...

  7. iOS系统分析(二)Mach-O二进制文件解析

    ➠更多技术干货请戳:听云博客 0x01  Mach-O格式简单介绍 Mach-O文件格式是 OS X 与 iOS 系统上的可执行文件格式,类似于windows的 PE 文件 与 Linux(其他 Un ...

  8. 读<<领域驱动设计-软件核心复杂性应对之道>>有感

    道可道,非常道. 名可名,非常名. 无名天地之始,有名万物之母. ---老子 关于标题 好久没写东西了,动笔的动机是看完了一本书,想写点总结性的东西,一是为了回顾一下梳理知识点,二是为了日后遗忘时能有 ...

  9. 【RDA】使用RDA(Remote Diagnostic Agent)工具对数据库进行健康检查

    [RDA]使用RDA(Remote Diagnostic Agent)工具对数据库进行健康检查 分类: Linux RDA英文全称叫做"Oracle Remote Diagnostic Ag ...

  10. 15天玩转redis —— 第十篇 对快照模式的深入分析

    我们知道redis是带有持久化这个能力了,那到底持久化成到哪里,持久化成啥样呢???这篇我们一起来寻求答案. 一:快照模式 或许在用Redis之初的时候,就听说过redis有两种持久化模式,第一种是S ...