资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Retina真实还原1px边框的解决方案-创新互联

射鸡师给你设计图是这样的!

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、虚拟空间、营销软件、网站建设、临颍网站维护、网站推广。

Retina真实还原1px边框的解决方案

然后你 boder:1px solid #ccc,然后到手机上一看,又粗又大,又长

然后,测试的妹子,受不了了……

然后,你说是的啊
……

Retina真实还原1px边框的解决方案

于是,你一张图片上去一看……

确实,不对呀!


Retina真实还原1px边框的解决方案

然后,怎么办了呢

第一:你想到的是:

设计图是750px,然后在iphon6上显示是375px

因为retina下1个 CSS 像素对应2个物理像素(多数是2个), 那么我们只需要想办法把border的宽度变为0.5px, 那么展现就是1个物理像素了.

那我设置

@media (min--moz-device-pixel-ratio: 2), (-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2), (min-resolution: 144dpi), (min-resolution: 2dppx), (-ms-high-contrast:active), (-ms-high-contrast:none) {
    *{
        border-width: .5px;
    }
}

然后,其它屏幕,不整除呢……0.x0x px

^^

这个有点扯蛋::因为,像素的定义:1px,就是显示的最小单位

定义:

像素是指基本原色素及其灰度的基本编码。[1]  像素是构成数码影像的基本单元,通常以像素每英寸PPI(pixels per inch)为单位来表示影像分辨率的大小。

例如300x300PPI分辨率,即表示水平方向与垂直方向上每英寸长度上的像素数都是300,也可表示为一平方英寸内有9万(300x300)像素。[2]

巴拉拉,省去xxxx万字哈……

我不喜欢科普哈!!!


然后,又怎么办呢!

我用图片:

1.BASE64:2像素图片,里面只有像素;

Retina真实还原1px边框的解决方案

  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAAXNSR…hZcwAADsMAAA7DAcdvqGQAAAAQSURBVBhXY5g5c+Z/BhAAABRcAsvqBShzAAAAAElFTkSuQmCC);  
  background-position: 0 0;   
  background-repeat: repeat-x;   
  background-size: 1px 1px;

2.渐变背景图片:

.border_top {   background-image: -webkit-linear-gradient(right,transparent 50%,#999 50%);   background-image: linear-gradient(to right,transparent 50%,#999 50%);   background-size: 1px 100%;   background-repeat: no-repeat;   background-position: center right;   border-top: 0 none;   padding-top: 1px; }

//下面是sass版本
@mixin boderHash($color:#efefef,$direction:"all"){
    background-repeat: no-repeat;
    @if($direction=="all"){
        border:none;
        padding: 1px;
        background-image:
                -webkit-linear-gradient(top, $color 50%, #999 50%),
                -webkit-linear-gradient(right, transparent 50%, $color 50%),
                -webkit-linear-gradient(bottom, transparent 50%, $color 50%),
                -webkit-linear-gradient(left, transparent 50%, $color 50%);
        background-image:
                linear-gradient(to top, transparent 50%, $color 50%),
                linear-gradient(to right, transparent 50%, $color 50%),
                linear-gradient(to bottom, transparent 50%, $color 50%),
                linear-gradient(to left,transparent 50%, $color 50%);
        background-size:
                100% 1px,
                1px 100%,
                100% 1px,
                1px 100%;
        background-position:
                top center,
                right center,
                bottom center,
                left center;

    }@else {
        border-#{$direction}: 1px solid ;
        background-image: -webkit-linear-gradient($direction, transparent 50%, $color 50%);
        background-image: linear-gradient(to $direction, transparent 50%, $color 50%);
        @if($direction=="left" or $direction=="right"){
            background-size: 100% 1px;
        }
        @if $direction=="top" or $direction=="bottom"{
            background-size:   1px 100% ;
        }


    }
}

第三:使用,伪类元素。

然后绝对定位:个人觉得性能消耗太大1

所以也不不再唧唧歪歪

其实:

我们知道的网站。都没有使用这些东西

不想,看图

如果有人叼你!!

你直接那这些图,干她!!

Retina真实还原1px边框的解决方案

Retina真实还原1px边框的解决方案

Retina真实还原1px边框的解决方案

转载请注明文章来处:Retina真实还原1px边框的解决方案 - css3,css3动画,css3新特性 - 周陆军的个人网站

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站名称:Retina真实还原1px边框的解决方案-创新互联
地址分享:http://cdkjz.cn/article/ddehce.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220