The div
with border: 2px solid red
has 2 pseudo elements, ::before
and ::after
, each with border-color: green
and border-color: blue
respectively. I'm trying to align the green
and blue
circles in the centre of the red
square. But unable to do so.
I've the following code:
.loader-container {
position: absolute;
width: 100%;
height: 100%;
left: 0px;
top: 0px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: aquamarine;
}
.loader {
border: 2px solid red;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.loader::after,
.loader::before {
content: "";
display: inline-block;
border-radius: 50%;
position: relative;
margin: 0 auto;
}
.loader::before {
border: 2px solid blue;
width: 50px;
height: 50px;
left: 25%;
}
.loader::after {
border: 2px solid green;
width: 100px;
height: 100px;
left: -25%;
}
<div class="loader-container">
<div class='loader'></div>
</div>
I also searched for the solution and found these:
But they do not work for me. Please help. Thank you.
Edit
The problem occurs due the different height
and width
of the ::before
and ::after
pseudo elements. Because, when height
and width
of both changed to the same value, then they aligned to the centre. However, I'm trying to align them in centre while keeping the height
and width
of each circle distinct.