div居中

2018-04-26  本文已影响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>
上一篇 下一篇

猜你喜欢

热点阅读