centering elements css code example
Example 1: css align center
<div class="parent">
<span>Hello World</span>
</div>
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: css center
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 3: centering css elements
.parent {
display: grid;
place-items: center;
}
Example 4: vertical align css
.container{
display: table;
}
.div-inside-container{
display: table-cell;
vertical-align: middle;
}
Example 5: css center div vertically
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
Example 6: how to center a div element
.box1{
width:80%;
margin:0 auto;
}