Search code examples
htmlcsscss-shapes

Creating a line with circle in the middle


So, I'm trying to achieve this result:

line with circle in the middle

This is what I got when I tried: https://jsfiddle.net/wvdkmjge/

.container {
  width: 100px;
  height: 1px;
  background-color: black;
}
.circle {
  display: inline-block;
  vertical-align: middle;
  width: 10px;
  height: 10px;
  background-color: transparent;
  border: solid 1px black;
  border-radius: 50%;
}
<div class="container">
  <div class="circle">

  </div>
</div>

Moreover, I want that I'll not see the border line on the circle. Any suggestions?


Solution

  • A small amendment to your code to position the elements and you get the effect you want to achieve.

    .container {
      width: 100px;
      height: 1px;
      background-color: black;
      position: relative;
    }
    .circle {
      display: inline-block;
      vertical-align: middle;
      width: 10px;
      height: 10px;
      background-color: white;
      border: solid 1px black;
      border-radius: 50%;
      position: absolute;
      top: -6px;
      left: calc(50% - 5px);
    }
    .blue {
      margin-top: 20px;
      background: #3EB2EF;
    }
    .blue .circle {
      background: #3EB2EF;
      border-color: #3EB2EF;
    }
    <div class="container">
      <div class="circle">
    
      </div>
    </div>
    
    <div class="container blue">
      <div class="circle">
    
      </div>
    </div>