centre align css code example
Example 1: css align center
//HTML
<div class="parent">
<span>Hello World</span>
</div>
//CSS
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: center with css
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Example 3: css align center
/* This works wonderfully when you know the size of
the thing you are centering. If you don’t know, or are
thinking it might change and want to be future proof,
try this: */
.centered {
position: fixed;
top: 50%;
left: 50%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
}
/* The translate value for transform is based off the size
of the element, so that will center nicely. */
Example 4: align center css
margin: auto;