How to center a div <div>
There are 3 Methods to centralize a div in css
HTML
<body>
<div class="parent">
<div class="child"></div>
</div>
</body>
Method #1
.parent{
background-color: red;
height: 300px;
width: 300px;
margin: 0 auto;
}
Method #2
.parent{
background-color: red;
height: 100vh;
width: 300wh;
display: flex;
justify-content: center;
align-items: center;
}
.child{
background-color: blue;
height: 300px;
width: 300px;
}
Method #3
.parent{
background-color: red;
height: 100vh;
width: 300wh;
display: grid;
place-items: center;
}
.child{
background-color: blue;
height: 300px;
width: 300px;
}
Method #4
.parent{
background-color: red;
height: 100vh;
width: 300wh;
}
.child{
background-color: blue;
height: 300px;
width: 300px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}