There are several ways to achieve centering, depending on the exact requirements.
One example is the positioning of a child absolutely (and the parent is relative), setting the field to automatic and the distance from each side to 0.
div.father {
border: 1px solid black;
height: 330px;
position: relative;
width: 330px;
}
div.son {
border: 1px solid black;
bottom: 0;
height: 100px;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
width: 100px;
}
<div class="father">
<div class="son"></div>
</div>
Run codeHide resultFor a complete guide to centering in CSS, I recommend this page . It has a complete guide for each type of centering.
source
share