用CSS画一条0.5px的直线

847 阅读1分钟

浏览器默认无法识别小于1像素

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 500px;
            background-color: #000;
            margin-bottom: 5px;
        }
        .line {
            height: 1px;
            /* 缩放0.5倍 */
            transform: scaleY(0.5);
            /*为了防止线模糊*/
            transform-origin: 50% 100%;
        }
        .line1 {
            height: 0.5px;
        }
        .line2 {
            height: 1px;
        }
    </style>
</head>
<body>
    <div class="line"></div>
    <div class="line1"></div>
    <div class="line2"></div>
</body>
</html>

chrome_R3YvlieYJk.png