Yes, text cropping 2020.
Luckily a new CSS prop to deal with this mess is on its way, but before it is widely adopted in all browsers (ie11 no longer) will have to deal with trimming the white space above and bellow the text the traditional hacky way.
So in my examples I have 2 elements - a div (block) and a span (inline). Both have ::before and ::after selectors applied to. In one hand the ::before pseudo-element has a negative value margin-bottom (to pull up the main element itself). On the other hand the ::after pseudo-element has a negative value margin-top (to push it up). There is a differense in the results:
Probably it is because of the formatting context.
Anyone who could shed some light on why in the first example the inner (salmon) container remains "hidden behind" the pseudo-elements and in the second example the inner container overlaps them??
Code: https://codepen.io/pollx/pen/MWyvoXm
.box{
box-sizing: border-box;
background: salmon;
/* border: 2px solid blue; */
}
.box::before,
.box::after {
content: " ";
display: block;
height: 5px;
width: 100%;
}
.box::before {
background: red;
margin-bottom: -8px;
}
.box::after {
background: green;
margin-top: -8px;
}
<div class="box">
Box - div
</div>
<br>
<span class="box">
Box - span
</span>
