I have a simple question that I can't seem to find the answer to, and it may be that I'm just not entering the correct search terms into Google, but after scratching my head while trying to gain a better understanding of this, I still turn up empty handed.
I have a span
element, that has a ::before
pseudo-element, nothing special, just a simple circle. However, I noticed that I have to absolutely position the pseudo-element in order for it to be visible. I found this rather odd and am not sure if I just don't fully understand pseudo-elements of this nature, or if I'm incorrectly implementing the idea.
Either way, here is an example with and without the absolute positioning.
html,
body {
margin: 0;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
span {
margin-bottom: 15px;
}
.no-absolute::before,
.absolute::before {
content: '';
width: 10px;
height: 10px;
margin-right: 5px;
border-radius: 50%;
background-color: #f33;
cursor: pointer;
}
.absolute {
position: relative;
}
.absolute::before {
position: absolute;
top: 4px;
left: -15px;
}
<span class="no-absolute">No Absolute</span>
<span class="absolute">Absolute</span>
Why does my ::before
pseudo-element have to be absolutely positioned in order to be visible?