transform: translate(-50%, -50%) 實現塊元素百分比下居中


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>position & transform: translate(-50%, -50%) 實現塊元素百分比下居中</title>
<style>
html,body {
        width: 100%;
        height: 100%;
        position: relative;
    }
    .box {
        width: 800px;
        height: 500px;
        background-color: #FFD914; 
    }
    .inside {
        width: 60%;
        height: 30%;
        background-color: red;
    }
    .center { 
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
</style>
</head>
<body>
    <div class="box center">
        <div class="inside center"></div>
    </div>
</body>
</html>

 


免責聲明!

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



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