HTML/CSS three small boxes are centered horizontally in a large box

HTML/CSS three small boxes are centered horizontally in a large box


Method 1: Turn the child box into an inline block
<!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>

Display:
Insert picture description here
Method 2: Put another box on the three small boxes.

<!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>

display:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_47021982/article/details/112251203