Hi, so some general background info, ::before
& :: after
are what are known as pseudo-element selectors.
When you have say some code in a <div id="div_id"></div>
, and decided to add more content without adding to html, the two pseudo-elements can come in handy.
with #div_id::before {}
whatever you add in the bracket show up positionally before the first child within the div.
with #div_id::after {}
whatever you add in the bracket show up positionally after the last child within the div.
All of the above distinction between pseudo-elements are when they are in their default inline position. They are moot when you change the position property.
Now here is where things get interesting. You literally cannot have one single element where you got background-image, on top of which you place more text and such, and have the background image to be more transparent than the rest, cannot be done.
So body::before{}
is a way to circumvent that limitation. Instead of directly telling the body to have a background-image
. It creates a pseudo-element that is positionally the same size as the body
, its parent. Then it fixes the position to be always the same regardless of scrolling, put a z-index to make sure it is lower than the body
elements, add the background image with low opacity.
Edited for clarity and typos.