HTML/CSS 三个小盒子在一个大盒子中水平居中

HTML/CSS 三个小盒子在一个大盒子中水平居中


方法一:把子盒子变成行内块
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .big {
     
     
            width: 600px;
            height: 600px;
            border: 1px solid red;
            text-align: center;
            font-size: 0;
        }
        .one, .two, .three {
     
     
            display: inline-block;
            width: 100px;
            height: 100px;
            border: 1px solid blue;
        }
    </style>
</head>
<body>
    <div class="big">
        <div class="one">1</div>
        <div class="two">2</div>
        <div class="three">3</div>
    </div>
</body>
</html>

显示:
在这里插入图片描述
方法二:给三个小盒子再套一个盒子。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .big {
     
     
            width: 600px;
            height: 600px;
            border: 1px solid red;
            
        }
        .brace {
     
     
            width: 398px;
            height: 300px;
            margin: 0 auto;
        }
        .one, .two, .three {
     
     
            float: left;
            width: 100px;
            height: 100px;
            border: 1px solid blue;
        }
    </style>
</head>
<body>
    <div class="big">
        <div class="brace">
            <div class="one">1</div>
            <div class="two">2</div>
            <div class="three">3</div>
        </div>
    </div>
</body>
</html>

显示:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_47021982/article/details/112251203