-1

I am trying to add lines between my circles, I've added ::after to css, but it only shows the line for the first circle, why it doesn't apply for every circle?

.segments > .item {
  display: flex;
}
.circle::after {
  content: '';
  background: grey;
  height: 5px;
  width: 50px;
  position: absolute;
  left: 0;
  top: 20px;
  z-index: -1;
}

.circle { 
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  background: red;
  display: grid;
  place-items: center;
  margin: 20px;
}
<div class="segments">
<div class="item">


<div class="circle">
test
</div>
<div class="circle">
test
</div>
<div class="circle">
test
</div>
<div class="circle">
test
</div>

</div></div>
Dave
  • 1
  • 1
  • 9
  • 38

1 Answers1

1

Set position: relative to the .circle
in order to make it able to contain the absolute ::after child - or in other words, make the absolute element relate to the first non-static positioned parent:

.segments>.item {
  display: flex;
}

.circle {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  background: red;
  display: grid;
  place-items: center;
  margin: 20px;
}

.circle::after {
  content: '';
  background: grey;
  height: 5px;
  width: 50px;
  position: absolute;
  left: 0;
  top: 20px;
  z-index: -1;
}
<div class="segments">
  <div class="item">
    <div class="circle">test</div>
    <div class="circle">test</div>
    <div class="circle">test</div>
    <div class="circle">test</div>
  </div>
</div>
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313