Hello. I am trying to understand the logic behind how .heart::before changes its shape the same way as .heart::after when I set its content to “” or an empty string. Also since .heart::before is like a reflection of .heart, couldn’t you just modify .heart’s content to “” and not having to use .heart::before at all?
::before and ::after are pseudo-elements. They show up as child elements of the element they are defined on.
If you inspect the DOM it looks like this (if the pseudo-elements have content set).
<div class="heart">
::before
other parent content
::after
</div>
The content property with an empty string is used with pseudo-elements to make them show up, otherwise, they won’t. You can add text as well but you usually wouldn’t do that if they are used as graphical elements.
The content property dictates what is rendered inside an element or pseudo-element.
For elements, it has only one purpose: specifying that the element renders as normal, or replacing the element with an image (and possibly some associated “alt text”).
For pseudo-elements and margin boxes, it is more powerful. It controls whether the element renders at all, can replace the element with an image, or replace it with arbitrary inline content (text and images).