Hairline! Ios implements border 0.5px and hairline0.5px

Source: Internet
Author: User

Hairline! Ios implements border 0.5px and hairline0.5px

On February 4, Ted O 'Connor proposed a "retina hairlines" solution, that is, a PX border can be displayed on the ratina screen. His solution is as follows:

 1 Standard border syntax: 2 div{ 3     border:1px solid black;     4 } 5 Retina hairline border syntax: 6 @media(-webkit-min-device-pixel-ratio:2){ 7     div{ 8         border-width:0.5px; 9     }10 }

It looks simple, right? Only one media query is needed, but I found it very painful after using it. Because many devices with ratina screens, such as iOS 7 and earlier versions, Android devices with devicePixelRatio greater than 2, OS X Mavericks, and earlier versions, their default values are border-width equal to 0, no border.

The following is my solution:

<!DOCTYPE html>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximun-scale=1,user-scalable=no">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.hairline {
display: flex;
justify-content: center;
align-items: center;
width: 50%;
height: 100px;
margin: 0 auto;
color: blue;
border: 3px solid #7c7c7c;
}
</style>

<body>
<div class="hairline">
hairline~
</div>
<script>
$(function(){
var agent = navigator.userAgent.toLowerCase() ;
var version;
if(agent.indexOf("like mac os x") > 0){
//ios
var regStr_saf = /os [\d._]*/gi ;
var verinfo = agent.match(regStr_saf) ;
version = (verinfo+"").replace(/[^0-9|_.]/ig,"").replace(/_/ig,".");
}

var version_str = version+"";
if(version_str != "undefined" && version_str.length >0){
version=version.substring(0,1);
if(version>=8){
$('.hairline').css('border-width','0.5px');
}
else{
}
}
});

</script>
</body>

The preceding DEMO can be run in Copy mode.

Usage: Add. hairline where PX is required.

Advantages:

Disadvantages: I have no HD screen PC and Mac at hand, so the above method does not support HD screen Mac and PC.

You are welcome to add children's shoes you are interested in ~

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.