<div>Block-level element</div>
div {
    width: 150px;
    height: 150px;
    background-color: yellow;
    margin-left: auto;
    margin-right: auto;
}
Result
<span>Inline-level element</span>
span {
    display: block; /* Changes the default inline display of the span to block */
    width: 150px;
    height: 150px;
    background-color: yellow;
    margin-left: auto;
    margin-right: auto;
}
Result
<div class="container">
    <span>Inline-level child element</span>
</div>
.container {
    background-color: orange;
    text-align: center; /* Horizontally centers inline content like text and images */
}
.container span {
    background-color: yellow;
}
Result
<div class="container">
    <div>Block-level child element</div>
</div>
.container {
    background-color: orange;
    display: flex;
    justify-content: center; /* Horizontally centers children (block or inline) */
}
.container div {
    width: 150px;
    height: 150px;
    background-color: yellow;
}
Result
<div class="container">
    <span>Inline-level child element</span>
</div>
.container {
    background-color: orange;
    display: flex;
    justify-content: center; /* Horizontally centers children (block or inline) */
}
.container span {
    background-color: yellow;
}
Result
<div class="container">
    <div>Block-level child element</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    display: flex;
    align-items: center; /* Vertically centers the child element (block or inline) */
}
.container div {
    width: 150px;
    height: 150px;
    background-color: yellow;
}
Result
<div class="container">
    <div>Block-level child element</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    position: relative;
}
.container div {
    width: 150px;
    height: 150px;
    background-color: yellow;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}
Result
<div class="container">
    <div>Block-level child element</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    display: flex;
    justify-content: center; /* Horizontally centers the child element */
    align-items: center;      /* Vertically centers the child element */
}
.container div {
    width: 150px;
    height: 150px;
    background-color: yellow;
}
Result
<div class="container">
    <div>Block-level child element</div>
</div>
.container {
    background-color: orange;
    height: 300px;
    position: relative;
}
.container div {
    width: 150px;
    height: 150px;
    background-color: yellow;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
}
Result