0

I've recently discovered the use of pseudo elements as graphical elements for design purposes. I'm trying to use a ::after element on a div to create horizontal dividers between sections, below:

.banner {
     position: relative;
     width: 100%;
     overflow: hidden;

}
 .banner__text, .banner__logo {
     width: 50%;
     float: left;
}
 .banner::after {
     content: '';
     position: absolute;
     left: 0;
     right: 0;
     border-bottom: 1px solid purple;
}
 
<div class="app">
  <div class="banner">
    <div class="banner__text">
      <h3>Hello World</h3>
      <p>longer string here</p>
    </div>
    <div class="banner__logo">
      <img src="//unsplash.it/159/250" />
    </div>
  </div>

  <div class="banner">
    <div class="banner__text">
      <h3>Hello World</h3>
      <p>longer string here</p>
    </div>
    <div class="banner__logo">
      <img src="//unsplash.it/159/250" />
    </div>
  </div>

 <div class="banner">
   <div class="banner__text">
     <h3>Hello World</h3>
     <p>longer string here</p>
   </div>
   <div class="banner__logo">
     <img src="//unsplash.it/159/250" />
   </div>
  </div>

</div>

However, you will notice that all the ::after elements stack right up at the top; is there a way I can have these absolutely positioned elements that have relatively positioned parents come after each div.banner?

Note: this question ::after pseudo element appearing before has such a specific answer I cannot determine the solution, although it is similar in scope...

UPDATE

Adding overflow: hidden to .banner fixes the after elements stacking up at the top, but they still appear before the rest of the content in each div.banner, while I'd like them after.

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
warren
  • 47
  • 1
  • 7

1 Answers1

1

Add bottom: 0 to make the dividers appear at the bottom of each .banner. For simplicity you'll probably want to use a bottom border instead of an ::after pseudo-element for this, however. Not everything needs to be done with one. Having said that, there is nothing wrong with experimenting.

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328