Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can't display the text with a z index

I’m trying to display a text upon the red colored after element with the increased z-index, but it fails. Maybe there is even a better approach to make a red bottom element and a padding
https://codepen.io/alex-filippovich/pen/QWZbXMe

.wrapper {
  margin: 0 auto;
}

.wrapper__img-outer {
  padding: 10px;
  height: 190px;
  width: 330px;
  background: center / cover no-repeat url("https://place-hold.it/330x190");
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.wrapper__img-outer:after {
  content: '';
  background-color: red;
  position: absolute;
  width: 100%;
  height: 54px;
  bottom: 0;
  left: 0;
  z-index: 1;
}

.text {
  z-index: 10;
}
<div class="wrapper">
  <div class="wrapper__img-outer">
    <div class="wrapper__img-top">
      <p class="text">text</p>
    </div>
    <div class="wrapper__img-bottom">
      <p class="text">text</p> // this text not being displayed
    </div>
  </div>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’ll need to set position to relative on the text class:

.text {
    z-index: 10;
    position: relative;
}
.wrapper {
  margin: 0 auto;
}
.wrapper__img-outer {
  padding: 10px;
  height: 190px;
  width: 330px;
  background: center / cover no-repeat url("https://place-hold.it/330x190");
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.wrapper__img-outer:after {
  content: '';
  background-color: red;
  position: absolute;
  width: 100%;
  height: 54px;
  bottom: 0;
  left: 0;
  z-index: 1;
}
.text {
  z-index: 10;
  position: relative;
}
<div class="wrapper">
    <div class="wrapper__img-outer">
        <div class="wrapper__img-top">
            <p class="text">Top text</p>
        </div>
        <div class="wrapper__img-bottom">
            <p class="text">Bottom text</p>
        </div>
    </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading