Creating CSS3 Circles connected by lines

前端 未结 8 1329
一个人的身影
一个人的身影 2020-12-02 05:19

I have to implement the following circle and line combination in CSS and I am looking for pointers on how to implement this effectively. The circles and lines should look li

8条回答
  •  暖寄归人
    2020-12-02 05:39

    You can achieve this effect with no additional markup using pseudo-elements and the adjacent sibling selector (~):

    css3 circles connected by lines

    li {
      width: 2em;
      height: 2em;
      text-align: center;
      line-height: 2em;
      border-radius: 1em;
      background: dodgerblue;
      margin: 0 1em;
      display: inline-block;
      color: white;
      position: relative;
    }
    
    li::before{
      content: '';
      position: absolute;
      top: .9em;
      left: -4em;
      width: 4em;
      height: .2em;
      background: dodgerblue;
      z-index: -1;
    }
    
    
    li:first-child::before {
      display: none;
    }
    
    .active {
      background: dodgerblue;
    }
    
    .active ~ li {
      background: lightblue;
    }
    
    .active ~ li::before {
      background: lightblue;
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    Demo on CodePen

提交回复
热议问题