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