首页 > 其他 > 详细

关于元素水平垂直居中

时间:2019-11-04 13:58:21      阅读:103      评论:0      收藏:0      [点我收藏+]

参考来源:https://blog.csdn.net/weixin_37580235/article/details/82317240#%E6%B0%B4%E5%B9%B3%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>center</title>
    <style>
        /*#outer{
            width: 500px;
            height: 300px;
            background-color: skyblue;
            position: relative;
        }*/
        /*已知高度*/
        /*#box{
            width: 100px;
            height: 100px;
            background-color: green;
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            margin: auto;
        }*/


        /*#outer{
            width: 500px;
            height: 300px;
            background-color: skyblue;
            position: relative;
        }*/
        /*未知高度*/
        /*#box{
            background-color: green;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translateX(-50%) translateY(-50%);
        }*/

        #outer{
            width: 500px;
            height: 300px;
            background-color: skyblue;
            display: flex;
            justify-content: center;
            align-items: center;
        }
         /*未知高度*/
        #box{
            background-color: green;
        }
    </style>
</head>
<body>
    <div id="outer">
        <div id="box">我需要居中</div>
    </div>
</body>
</html>

 

关于元素水平垂直居中

原文:https://www.cnblogs.com/wodeqiyuan/p/11791231.html

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