top:0;bottom:0;left:0;right:0;同時使用的效果


<!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 {
            width: 600px;
            height: 600px;
            background: blue;
            position: relative
        }
        
        .div1 {
            /* width: 200px;
            height: 200px; */
            background: red;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="div1"></div>
    </div>


</body>

</html>

left:0;right:0;top:0;bottom:0;再加上margin:auto,會使div1居中,如果div1,沒有寬高,則會繼承父集的寬高。適合body 內的遮罩,

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM