margin
<div class="box box1"></div>.box {
width: 300px;
height: 200px;
background-color: #ccc;
}
.box1 {
margin: 0 auto;
}flex
<div class="box2-wrap">
<div class="box box2"></div>
</div>.box2-wrap {
display: flex;
gap: 10px;
justify-content: center;
align-items: center;
}
.box {
width: 300px;
height: 200px;
margin-bottom: 20px !important;
background-color: #ccc;
}positionとtransform
<div class="box3-wrap">
<div class="box box3"></div>
</div>.box3-wrap {
width: 100%;
height: 100%;
position: relative;
}
.box {
width: 300px;
height: 200px;
background-color: #ccc;
}
.box3 {
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%,-50%);
}grid
<div class="box4-wrap">
<div class="box box4"></div>
</div>.box3-wrap {
width: 100%;
height: 100%;
}
.box {
width: 300px;
height: 200px;
background-color: #ccc;
}