Using Flexbox
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.item {
width: 40%;
height: 20%;
background-color: lightblue;
}
Using Grid
.container {
display: grid;
place-items: center;
height: 100vh;
}
.item {
width: 40%;
height: 20%;
background-color: lightblue;
}
Using Absolute Positioning
.container {
position: relative;
height: 100vh;
}
.item {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 40%;
height: 20%;
background-color: lightblue;
}
Using Line-Height
.container {
height: 100vh;
text-align: center;
}
.item {
display: inline-block;
line-height: 100vh;
vertical-align: middle;
background-color: lightblue;
}