Centering
Horizontal Centering
Inline Elements
<div class="desk">
<span class="plate"></span>
<span class="plate"></span>
</div>
.desk {
text-align: center;
}
.desk {
display: flex;
justify-content: center;
}
.desk {
display: grid;
justify-content: center;
}
Block Elements
.plate {
width: 120px;
height: 120px;
margin-left: auto;
margin-right: auto;
}
.tray {
display: flex;
margin-left: auto;
margin-right: auto;
}
.desk {
display: flex;
justify-content: center;
}
.plate {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.plate {
position: absolute;
left: 50%;
margin-left: -60px;
}
Vertical Centering
Inline Elements
.desk {
padding-top: 24px;
padding-bottom: 24px;
}
.desk {
text-align: center;
}
.plate,
.fork,
.knife {
vertical-align: middle;
}
.desk {
display: flex;
justify-content: center;
align-items: center;
}
Block Elements
.plate {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.plate {
position: absolute;
top: 50%;
margin-top: -60px;
}
.desk {
display: grid;
align-items: center;
}
Horizontal & Vertical Centering
Inline Elements
.plate {
text-align: center;
padding-top: 24px;
padding-bottom: 24px;
}
Other Element Types
.plate {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.plate {
display: flex;
justify-content: center;
align-items: center;
}
.desk {
display: grid;
place-items: center;
}