0

I have a background with text that needs to go above a line.

enter image description here

The parent element is position: relative. The line is position: absolute. The background is position: relative. The elements are in that order.

HTML

<div class="timeline">
  <div class="line"></div>
    <div class="section_text_bg_color mb-8">
      <div class="row">
         <div class="text WYSIWYG-styles text_container">...</div>
      </div>
    </div>
  <div class="container-fluid">...</div>
</div>

SCSS

.timeline {
  position: relative;
  z-index:1;

  .line {
    position: absolute;
    content: "";
    height: 100%;
    width: 1px;
    top: 0;
    left: 50%;
    background-color: $primary-color-2;
    z-index: -1;

    @include media-breakpoint-down(sm) {
      display: none;
    }
  }

  .section_text_bg_color {
    position: relative;
    padding: 40px;
    margin-top: 0;
    z-index: 3;
  }

  #first.section_text_bg_color {
    margin-top: -80px;

    @include media-breakpoint-down(sm) {
      margin-top: 0;
    }
  }

The line and background are siblings of the timeline element.

Based on this post, I have to set the parent to z-index:1, the line to z-index:-1, and section_text_bg_color to z-index: 3. If I remove the parent z-index the line will go behind the parent div.

If my understanding is correct, I created a stacking order in the parent element, but am only asking for one of the siblings to be above another, not a child above its parent.

I don't see what the issue is here.

Any help is appreciated.

SedStan
  • 13
  • 4
  • Despite your question has been closed, i don't think a problem is caused by stacking context, as suggested in title. I noticed small bug in HTML though, you are lacking one , is it only example problem? – Stanislav Šolc Jul 14 '21 at 08:46
  • @StanislavŠolc Yes. I cut out some unnecessary code that was not relevant to the question. – SedStan Jul 14 '21 at 09:02
  • Ok, i don't see problem in your example then. I created example here, and everything works fine, as we both expect. https://stackblitz.com/edit/js-ufxyem. Let me know if you find where was a problem... – Stanislav Šolc Jul 14 '21 at 09:36
  • @StanislavŠolc I tried this, but something else is going on. I updated the question. – SedStan Jul 14 '21 at 14:25
  • 1
    It turns out the background div had an opacity on it. :/ – SedStan Jul 14 '21 at 15:42

0 Answers0