1px

时间:2024-01-03 14:18:20

Retina屏的移动设备如何实现真正1px的线?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<title></title>
</head>
<body>
<div style="width:100px;height:0.5px;background:red;margin:10px;"></div> <div style="width:100px;height:1px;background:red;margin:10px;"></div> <div style="width:100px;height:1px;background:red;margin:10px;-webkit-transform: scaleY(0.5);transform:scaleY(0.5);-webkit-transform-origin:0 0;transform-origin: 0 0;"></div>
</body>
</html>

1px

if (window.devicePixelRatio && devicePixelRatio >= 2) {
var testElem = document.createElement('div');
testElem.style.border = '.5px solid transparent';
document.body.appendChild(testElem);
if (testElem.offsetHeight == 1)
{
document.querySelector('html').classList.add('hairlines');
}
document.body.removeChild(testElem);
}