zoukankan      html  css  js  c++  java
  • CSS3实现0.5px的边框

    单边框0.5px,可以用以下方式:

    方式一:border + border-image + 线性渐变linear-gradient

    <div class="border">0.5像素边框</div>
    <style>
        .border {
             200px;
            height: 200px;
            margin: 0 auto;
            border-bottom: 1px solid transparent;
            border-image: linear-gradient(to bottom,transparent 50%, red 50%) 0 0 100%/1px 0;
        }
    </style>
    

    方式二:定位 + 伪元素 + background + 线性渐变linear-gradient

    <div class="border">0.5像素边框</div>
    <style>
        .border {
             200px;
            height: 200px;
            margin: 0 auto;
            position: relative;
        }
        .border::before {
            content: " ";
            position: absolute;
            left: 0;
            bottom: 0;
             100%;
            height: 1px;
            background-image: linear-gradient(to bottom, transparent 50%, red 50%);
        }
    </style>
    

    方法三:定位 + 伪元素 + transfrom缩放(scale)(此方法亲测有效)

    <div class="border">0.5像素边框</div>
    <style>
        .border {
             200px;
            height: 200px;
            margin: 0 auto;
            position: relative;
        }
        .border::after {
            content: " ";
            position: absolute;
            left: 0;
            bottom: 0;
             100%;
            height: 1px;
            background: red;
            transform: scaleY(0.5);
        }
    </style>
    

    对于需要四边0.5像素边框,可以用以下方式:

    方式:定位 + 伪元素 + transfrom缩放(scale)

    <div class="border">0.5像素边框~~~~</div>
    <style>
        .border {
             200px;
            height: 200px;
            margin: 0 auto;
            position: relative;
        }
        .border::before {
            content: " ";
            position: absolute;
            top: 0;
            left: 0;
             200%;
            height: 200%;
            border: 1px solid red;
            transform-origin: 0 0;
            transform: scale(0.5);
        }
    </style>
    

    参考博客:http://www.fly63.com/article/detial/5825

    今天你学习了吗!!!
  • 相关阅读:
    HDU 1813 Escape from Tetris
    BZOJ 2276 Temperature
    BZOJ 4499 线性函数
    BZOJ 3131 淘金
    HDU 5738 Eureka
    POJ 2409 Let it Bead
    POJ 1286 Necklace of Beads
    POJ 1696 Space Ant
    Fox And Jumping
    Recover the String
  • 原文地址:https://www.cnblogs.com/nayek/p/13474709.html
Copyright © 2011-2022 走看看