首页 > 其他 > 详细

transform: translate(-50%, -50%) 实现块元素百分比下居中

时间:2017-03-01 16:30:01      阅读:273      评论:0      收藏:0      [点我收藏+]
<!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>

 

transform: translate(-50%, -50%) 实现块元素百分比下居中

原文:http://www.cnblogs.com/hjbky/p/6484639.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!