CENTERING DIV CSS code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: center a div css
.center {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Example 3: centering css elements
.parent {
display: grid;
place-items: center;
}
Example 4: css vertical center
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
Example 5: css align center vertical and horizontal
.parent-class {
display: flex;
align-items: center;
justify-content: space-around;
}
Example 6: css centering
.parent {
display: flex;
align-items: center;
justify-content: center;
}
.parent {
display: flex;
align-items: center;
justify-content: center;
}
.parent {
position: relative;
}
.child {
position: absolute;
left: 50%;
right: 50%;
transform: translate(-50%, -50%);
}