Search code examples
cssalignmentgeometrytext-align

Circle and text alignment CSS3


I would like to align the text under the circle, perfectly on the middle.

Here a snippet (I simplified everything because circle and text are handled by angular so they are some difference between my screenshot and the snippet)

.circle2 {
  border-radius: 50%;
  width: 18px;
  height: 18px;
  background: RoyalBlue;
  display: inline-block;
  z-index: 2;
}
.wrapper2 {
  display:flex;
  width:100%;
  justify-content: space-around;
  position:relative;

}
.wrapper2:after {
  position:absolute;
  content:'';
  display:block;
  width: 100%;
  top:7px;
  height: 3px;
  background: RoyalBlue;

}
.advanced2 {
  width: 18px;
  height: 18px;
}
.circleActive2 {
  border-radius: 50%;
  width: 25px;
  height: 25px;
  background: RoyalBlue;
  display: inline-block;
}
<div class="w3-container">
  <div class="wrapper2">
    <span>
    <span><div class="circle2 advanced2" ></div>test</span>
    <span><div class="circle2 advanced2 circleActive2" ></div>test2</span>
    <span><div class="circle2 advanced2" ></div>test3</span>
        <span><div class="circle2 advanced2" ></div>test4</span>
        <span><div class="circle2 advanced2" ></div>test5</span>
      </span>
 </div>
</div>


Solution

  • .circles {
      display: flex;
      width: 100%;
      justify-content: space-around;
      position: relative;
    }
    
    .circles:after {
      position: absolute;
      content: '';
      display: block;
      width: 100%;
      top: 7px;
      height: 3px;
      background: RoyalBlue;
    }
    
    .circles > div {
      display: flex;
      flex-direction: column;
      align-items: center;  
    }
    
    .circle {
      border-radius: 50%;
      width: 17px;
      height: 17px;
      background: RoyalBlue;
    }
    
    .circle.active {
      width: 25px;
      height: 25px;
      margin-top: -4px;
    }
    <div class="circles">
      <div><span class="circle"></span>test</div>
      <div><span class="circle active"></span>test2</div>
      <div><span class="circle"></span>test3</div>
      <div><span class="circle"></span>test4</div>
      <div><span class="circle"></span>test5</div>
    </div>