div居中

作者: 月尚 | 来源:发表于2018-04-26 15:23 被阅读0次
捕获.PNG

设置子元素div 和 父级div 宽高一样
使得子元素div在父级的div里面居中

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        .wraper{
            width: 200px;
            height: 200px;
            background-color: red;
            padding: 50px;
        }
        .content{
            width: 80px;
            height: 80px;
            background-color: yellow;
        }

        /*内外层宽高相同*/
        /*子元素div会在父级的div里面居中*/
        .wrapersss{
            width: 100px;
            height: 100px;
            background-color: red;
            /*膨胀,将内容撑开*/
            padding: 50px;
        }
        .contentsss{
            width: 100px;
            height: 100px;
            background-color: yellow;
        }
    </style>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div class="wraper">
        <div class="content">1</div>
    </div>
    <br>
    <div class="wrapersss">
        <div class="contentsss">2</div>
    </div>
</body>
</html>

相关文章

网友评论

      本文标题:div居中

      本文链接:https://www.haomeiwen.com/subject/scxmlftx.html