I'm trying to learn the basics of front-end web development and I'm struggling to understand why body::before
behaves the way it does. I have the following 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;
}
This way the background will appear moved to the bottom-left by some pixels (CodePen screenshot), and will only cover the entirety of the screen if top/bottom and left/right are set to 0. Why does the body::before
position behave that way but normal body's position doesn't? Also, why doesn't the body::before
even appear if the position is set to relative?