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 ~