1

I am trying to apply the solution found in the this question, but it is not working in my case.

I want to bring the red circle above the green line.

.box{
  border: 1px solid blue;
  height: 100px;
  position: relative;
  width: 100px;
}
.dot{
  background: red;
  border-radius: 50%;
  height: 30px;
  width: 30px;
  position: absolute;
  right: -15px;
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}
.dot:after{
  background: green;
  content: '';
  height: 100px;
  width: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  z-index: -1;
}
<div class="box">
  <div class="dot"></div>
</div>
<div class="box">
  <div class="dot"></div>
</div>
Community
  • 1
  • 1
Felix A J
  • 6,300
  • 2
  • 27
  • 46
  • add a z-index to `.dot` and make sure it's greater than what `.dot:after` has – slash197 Mar 17 '16 at 13:20
  • @slash197 The problem with that approach is that the `.dot:after` is a child of `.dot`. It therefore will never have a lower `z-index` than its parent. `z-index` uses the closest relative parent for reference on its stacking order. That's also why in a document you can have a `
    ` section with z indexes through to the thousands and still have the site `
    ` stack higher than them (provided `
    ` has a lower index than `
    ` for instance).
    – Joseph Marikle Mar 17 '16 at 13:28

1 Answers1

1

Can't you just make the red dot be an :after rather than the element styles itself?

.box{
  border: 1px solid blue;
  height: 100px;
  position: relative;
  width: 100px;
}
.dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 100%;
  z-index: 1;
}
.dot:after{
  background: red;
  content: '';
  border-radius: 50%;
  height: 30px;
  width: 30px;
  position: absolute;
  right: -15px;
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}
.dot:before{
  background: green;
  content: '';
  height: 100px;
  width: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
<div class="box">
  <div class="dot"></div>
</div>
<div class="box">
  <div class="dot"></div>
</div>
Joseph Marikle
  • 76,418
  • 17
  • 112
  • 129