This page shows you how to arrange horizontally CSS elements.
See CSS Block - Align (Left, Center, Right)
See CSS Flex - Align (Left, Right, Center)
.container {
display: flex;
justify-content: center;
align-items: center;
}
.child {
border: 1px solid aqua;
}
<div class="container">
<div class="child">Am I ...?</div>
</div>
See also the justify-content article for more values such as left are right
.container {
display: grid;
place-items: center
}
<div class="container">
<div style="border:1px solid black">Am I ...?</div>
</div>
In case of absolute positioning:
.relative {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
}
where:
On Bootstrap, this is the class:
With a flex parent, the auto marging value will push the element to:
Demo:
.parent {
display: flex;
margin-top: 40px; /* Below the control button of the preview */
}
.child {
margin-left: auto
}
<div class="parent">
<div class="child">
Child to the right
</div>
</div>