Retina 显示屏上可以有 0.5 像素的边框吗?
在 iPhone 4 或 iPhone4S 上的 Mobile Safari 上,是否可以设置 0.5 像素宽的 div 边框?
On Mobile Safari on an iPhone 4 or iPhone4S, can you have a border of a div that is 0.5px wide?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用
border-width: 0.5px
Safari 8(iOS 和 OS X 中)引入了
border-width: 0.5px
。如果您准备好接受当前版本的 Android 以及旧版本的 iOS 和 OS X 将仅显示常规边框(我认为这是一个公平的妥协),您可以使用它。但您不能直接使用它,因为不知道
0.5px
边框的浏览器会将其解释为0px
。无边界。因此,您需要做的就是在支持时向您的元素添加一个类:
然后,使用视网膜细线变得非常简单:
最重要的是,您可以使用 border-radius 来使用它。您可以轻松地将其与 4 个边框(上/右/下/左)一起使用。
来源:http://dieulot.net/css-retina-hairline
Use
border-width: 0.5px
Safari 8 (in both iOS and OS X) brings
border-width: 0.5px
. You can use that if you’re ready to accept that current versions of Android and old versions of iOS and OS X will just show a regular border (a fair compromise in my opinion).You can’t use this directly though, because browsers that don’t know about
0.5px
borders will interpret it as0px
. No border. So what you need to do is add a class to your<html>
element when it is supported:Then, using retina hairlines becomes really easy:
Best of all, you can use border-radius with it. And you can use it with the 4 borders (top/right/bottom/left) as easily.
Source: http://dieulot.net/css-retina-hairline
我写了一篇不同技术的概述:
半像素边框
缺点:
border-image
border.gif 是一个 6×6 像素图像:
优点:
缺点:
多个背景图像
“如何使用 CSS 瞄准视网膜屏幕上的物理像素”描述了如何绘制一条线。画4条线,我们就有了一个边框。
优点:
缺点:
放大和缩小
Priit Pirita 已经在这里提到过。
I wrote an overview of different techniques:
Half-pixel border
Cons:
border-image
border.gif is a 6×6 pixel image:
Pros:
Cons:
Multiple background images
“How to target physical pixels on retina screens with CSS” describes how to draw a line. Draw 4 lines and we have a border.
Pros:
Cons:
Scale up and down
Mentioned here already by Priit Pirita.
是的。使用规模。下面的样式会给你发际线
当你需要所有边时,最好的方法是用 :after 或 :before CSS 伪类复制 DIV,将边框应用于该伪类,使其大小两倍,然后使用 Transform:scale 缩放它减少到一半。
更具体地说(以及所有正在使用的技巧)在这里 http ://atirip.com/2013/09/22/yes-we-can-do-fraction-of-a-pixel/
Yes. Use scale. The style below will give you hairline
When you need all sides, then the best way is to repliacte the DIV with :after or :before CSS pseudoclass, apply border to that pseudoclass, make it twice the size and then scale it with transform:scale down to half.
More specificly (and all those tricks in use too) here http://atirip.com/2013/09/22/yes-we-can-do-fraction-of-a-pixel/
我为此使用 CSS 自定义属性。它更加优雅(恕我直言)。
I use CSS custom properties for this. It is much more elegant (IMHO).
我还发现这个方法有效(iOS7):
Also I've found this method working (iOS7):
Apple 在 OSX Yosemite 和 iOS 8 中添加了对此的支持。
Apple added support for this in OSX Yosemite and iOS 8.
通过 CSS,可以使用 box-shadow 和 spread radius 来完成。该方法的解释如下:
http://bradbirdsall.com/mobile-web-in-high-resolution
这是从上面的链接复制的:
With CSS that can be done using box-shadow and spread radius. The approach is explained here:
http://bradbirdsall.com/mobile-web-in-high-resolution
This is copied from the link above:
分享我编写并一直在使用的 Sass/SCSS + Compass mixin:
CSS 示例:
Sharing a Sass/SCSS + Compass mixin I wrote and I've been using:
CSS example:
我不确定你的意思到底是什么。如果您询问是否可以在 iPhone 4 上绘制 1 像素的边框(该边框是 iphone3G 上边框物理尺寸的 1/2),那么可以。 CoreGraphics 使用点而不是像素。通过下面的方法可以看到,你可以指定一个float:
由于1point != 1px,所以在iPhone4上你可以通过指定0.5point来指定1px。
在这里阅读它
I'm not sure what you mean exactly. If you are asking if you can draw a border of 1 px on an iPhone 4 which would be 1/2 the physical size of the border on an iphone3G, then yes. CoreGraphics uses points instead of pixels. As you can see by the following method, you can specify a float:
Since 1point != 1px, you can specify 1px on an iPhone4 by specifying 0.5point.
Read up on it here