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