<div>ブロックレベル要素</div>
div {
    width: 150px;
    height: 150px;
    background-color: pink;
    margin-left: auto;
    margin-right: auto;
}
結果画面
<span>インラインレベル要素</span>
span {
    display: block; /* span要素のdisplayの初期値はinlineであり、インラインレベル要素をブロックレベル要素に変更しています */
    width: 150px;
    height: 150px;
    background-color: pink;
    margin-left: auto;
    margin-right: auto;
}
結果画面
<div class="container">
    <span>インラインレベルの子要素</span>
</div>
.container {
    background-color: orange;
    text-align: center; /* 左右に余白がある親要素の横幅を基準に、子要素のテキストや画像などのインラインレベルコンテンツを中央揃えにします */
}
.container span {
    background-color: pink;
}
結果画面
<div class="container">
    <div>ブロックレベルの子要素</div>
</div>
.container {
    background-color: orange;
    display: flex;
    justify-content: center; /* 子要素(ブロックレベル要素、インラインレベル要素)を横(水平)方向の中央に揃えます */
}
.container div {
    width: 170px;
    height: 170px;
    background-color: pink;
}
結果画面
<div class="container">
    <span>インラインレベルの子要素</span>
</div>
.container {
    background-color: orange;
    display: flex;
    justify-content: center; /* 子要素(ブロックレベル要素、インラインレベル要素)を横(水平)方向の中央に揃えます */
}
.container span {
    background-color: pink;
}
結果画面
<div class="container">
    <div>ブロックレベルの子要素</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    display: flex;
    align-items: center; /* 子要素(ブロックレベル要素、インラインレベル要素)を縦(垂直)方向の中央に揃えます */
}
.container div {
    width: 170px;
    height: 170px;
    background-color: pink;
}
結果画面
<div class="container">
    <div>ブロックレベルの子要素</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    position: relative;
}
.container div {
    width: 170px;
    height: 170px;
    background-color: pink;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}
結果画面
<div class="container">
    <div>ブロックレベルの子要素</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    display: flex;
    justify-content: center; /* 子要素を横(水平)方向の中央に揃えます */
    align-items: center; /* 子要素を縦(垂直)方向の中央に揃えます */
}
.container div {
    width: 170px;
    height: 170px;
    background-color: pink;
}
結果画面
<div class="container">
    <div>ブロックレベルの子要素</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    position: relative;
}
.container div {
    width: 170px;
    height: 170px;
    background-color: pink;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
}
結果画面