HTML / CSS3つの小さなボックスが大きなボックスの水平方向の中央に配置されます
方法1:子ボックスをインラインブロックに変換する
<!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>
表示:
方法2:3つの小さなボックスに別のボックスを置きます。
<!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>
表示: