center content in div code example
Example 1: center a div in css
.container {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: css align center
<div class="parent">
<span>Hello World</span>
</div>
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 3: css align items vertical center
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 4: center with css
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Example 5: css center text in div
parent-element {text-align:center;}
parent-element {position: relative;}
element-to-be-centered {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
Example 6: center content in div
.container {
height: 200px;
display: flex;
align-items: center;
justify-content: center;
}
.item {
width: 10em;
}