Z-indexnot working on pseudo-elements

Hello team, I am working on some pseudo-elements with backgroung-images, and my problem is that no matter if i set the ::before and the ::after with pisition: absolute and z-index lower than the parent element, they don't go under the parent element covering my patent element. Why is that? And how can i solve it?

.tartkozep::before {
  content: " ";
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: -20px;
  z-index: -1;
  background-image: url('/tart-szel.jpg');
  background-repeat: no-repeat;
  background-size: contain;
}

.tartkozep::after {
  content: " ";
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 350px;
  z-index: -1;
  background-image: url('/tart-szel.jpg');
  background-repeat: no-repeat;
  background-size: contain;
}

.tartkozep {
  margin: 0 0;
  width: 100%;
  position: relative;
  top: 20px;
  left: 0px;
  z-index: 1;
  background-image: url('/tart-kozep.jpg');
  background-size: contain;
  background-repeat: repeat-y;
  height: 420px;
}
Was this page helpful?