0

I have a header and I want to put a dashed horizontal line to the left and right side of this header as you can see in the jsfiddle

https://jsfiddle.net/uLake5g3/9/

This is my HTML:

<div class = "spotlight">
  <div class = "container spotlight__main">
    <h2><span class  ="background__red">In the spotlight</span></h2>
  </div>
</div>

And this is my CSS:

h2 > span {
  position: relative;
  display: inline-block;
}

h2 > span:before,
h2 > span:after {
  content: "";
  position: absolute;
  top: 50%;
  border-bottom: 1px dashed;
  width: 96rem;
  margin: 0 auto;
  vertical-align: center;
}

h2 > span:before {
  right: 100%;
}

h2 > span:after {
  left: 100%;
}

I want to have the dashed lines inside the spotlight_main his border, but they are going outside.

FoxOnFireHD
  • 145
  • 11
  • Another option is to use Flexbox, refer to :after :before as regular Html elements: https://codepen.io/Liveindream/pen/yLyjeVz – Liveindream Jan 10 '20 at 15:40

2 Answers2

0

you can try:

h2:before{
    border-bottom: 1px dashed;
    color: #fff;
    content: "";
    left:0;
    position: absolute;
    right:0;
    top: 50%;
}
oussama
  • 16
  • 2
0

You could add overflow: hidden; to the container.

I've added a few additional rules here to make it clear that the dashes aren't extending beyond the container.

.container {
  overflow: hidden;
  width: 400px;
  margin: auto;
  text-align: center;
}

h2>span {
  position: relative;
  display: inline-block;
}

h2>span:before,
h2>span:after {
  content: "";
  position: absolute;
  top: 50%;
  border-bottom: 1px dashed;
  width: 96rem;
  margin: 0 auto;
  vertical-align: center;
}

h2>span:before {
  right: 100%;
}

h2>span:after {
  left: 100%;
}
<div class="spotlight">
  <div class="container spotlight__main">
    <h2><span class="background__red">In the spotlight</span></h2>
  </div>
</div>
thingEvery
  • 3,368
  • 1
  • 19
  • 25