解決position: fixed;彈框的中input自定義表單1px border看起來模糊問題

出現的問題:

我們想要的效果:

 

結構:

<body>
    咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩
    <div class="box">
        <div class="box_bg"></div>
        <div class="box_bubble">
            <h2>hello!muzidigbig</h2>
            <input type="text">
        </div>

    </div>
</body>

出現問題的樣式:

    <style>
        .box {
            position: fixed;
            left: 0;
            top: 0;
            height: 100%;
            width: 100%;
            text-align: center;
        }
        
        .box_bg {
            position: fixed;
            left: 0;
            top: 0;
            z-index: -1;
            width: 100%;
            height: 100%;
            background-color: #000;
            filter: alpha(opacity=30);
            opacity: .3;
        }
        
        .box_bubble {
            background: #fff;
            width: 400px;
            padding: 50px;
            text-align: left;
            border: 2px solid pink;
            /* 這種定位方式會使input表單設有border的邊框線加粗 */
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }
        
        input {
            border: 1px solid #666;
        }
    </style>

我們想要的效果的樣式:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            position: fixed;
            left: 0;
            top: 0;
            height: 100%;
            width: 100%;
            text-align: center;
        }
        
        .box::before {
            content: "";
            height: 100%;
            display: inline-block;
            vertical-align: middle;
        }
        
        .box_bg {
            position: fixed;
            left: 0;
            top: 0;
            z-index: -1;
            width: 100%;
            height: 100%;
            background-color: #000;
            filter: alpha(opacity=30);
            opacity: .3;
        }
        
        .box_bubble {
            background: #fff;
            width: 400px;
            padding: 50px;
            text-align: left;
            border: 2px solid pink;
            
            position: static;
            top: auto;
            left: auto;
            transform: none;
            margin-left: 0;
            display: inline-block;
            vertical-align: middle;
        }
        
        input {
            border: 1px solid #666;
        }
    </style>
</head>

<body>
    咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩咩
    <div class="box">
        <div class="box_bg"></div>
        <div class="box_bubble">
            <h2>hello!muzidigbig</h2>
            <input type="text">
        </div>

    </div>
</body>

</html>

這裏我也有疑問   就是不知道下面這塊代碼表達的原理是什麼?

        .box::before {
            content: "";
            height: 100%;
            display: inline-block;
            vertical-align: middle;
        }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章