I am currently diving into the world of front-end web development and I am having some trouble grasping the concept behind the behavior of body::before
. Below is a snippet of my CSS code:
body::before {
content: "";
position: fixed;
width: 100%;
height: 100%;
background: linear-gradient(rgba(0, 0, 0, 0), rgba(255, 255, 0, 0.45)), url(https://cdn.pixabay.com/photo/2015/03/03/05/56/avenue-656969_960_720.jpg);
background-repeat: no-repeat;
background-size: cover;
z-index: -1;
}
With this setup, the background seems to shift towards the bottom-left slightly (CodePen screenshot), and only fully covers the screen when top/bottom and left/right are both set at 0. Why does the positioning behavior of body::before
differ from that of the regular body? Furthermore, why does body::before
not appear at all if the position is set as relative?