css centring code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: css vertical center
/* No Flexbox */
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
/* With Flexbox */
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
Example 3: how to center an ing with block display
img{
display: block;
margin-left: auto;
margin-right: auto;
}
Example 4: how to put container in center of page
#container
{
width: 400px;
margin-left: auto;
margin-right: auto;
}