<div class="g-wrap">
<div class="g-container absolute">
<div class="sub"></div>
</div>
<div class="g-container autobot">
<div class="sub"></div>
</div>
<div class="g-container flex">
<div class="sub"></div>
</div>
<div class="g-container grid">
<div class="sub"></div>
</div>
</div>
<div class="g-tips">
<div><span>absolute</span></div>
<div><span>autobot</span></div>
<div><span>flex</span></div>
<div><span>grid</span></div>
</div>
xxxxxxxxxx
.g-wrap {
display: flex;
justify-content: space-around;
padding: 10px;
box-sizing: border-box;
}
.g-tips {
margin-top: 24px;
display: flex;
justify-content: space-around;
font-size: 14px;
font-weight: bold;
div {
width: 250px;
text-align: center;
}
span {
color: deeppink;
}
}
.g-container {
width: 200px;
height: 200px;
background: #999;
}
.sub {
width: 100px;
height: 100px;
background: #333;
}
.absolute {
position: relative;
& > div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.absolute {
position: relative;
& > div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.autobot {
display: flex;
& > div {
margin: auto;
}
}
.flex {
display: flex;
justify-content: center;
align-items: center;
}
.grid {
display: grid;
place-content: center;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.