Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a horizontal line between two circles with CSS?

How do I draw a horizontal line in between 2 circles in CSS?

It has to be in the middle of them just as shown in the screenshot.

Example here:

enter image description here

I have drawn the 2 circles, but don't know how to connect them.

#status-buttons a {
  color: black;
  display: inline-block;
  font-size: 17px;
  font-weight: normal;
  margin-right: 0;
  text-align: center;
  text-transform: uppercase;
  min-width: 150px;
  text-decoration: none;
}
#status-buttons a:hover {
  text-decoration: none;
}
#status-buttons a.active span {
  color: white;
  background: #ACCF5B;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
#status-buttons span {
  color: white;
  background: #22bacb;
  display: block;
  height: 45px;
  margin: 0 auto 10px;
  padding-top: 20px;
  width: 60px;
  border-radius: 50%;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
<div id="status-buttons" class="text-center">
  <a href="#/form/regalo" class="active"><span>1</span> Step 1</a>
  <a href="#/form/tusdatos"><span>2</span> Step 2</a>
</div>

See demo on JSFiddle

like image 285
nerlijma Avatar asked Oct 17 '16 00:10

nerlijma


People also ask

How do I make a horizontal line in CSS?

Its simple to add a horizontal line in your markup, just add: <hr>. Browsers draw a line across the entire width of the container, which can be the entire body or a child element. Originally the HR element was styled using attributes.

Can you style a horizontal line CSS?

A horizontal rule is used to provide a visual break and divide content. Like other HTML elements, horizontal rules can be styled using CSS (and SVG). This means that they don't have to look like boring, plain horizontal lines.

How do you make a half circle outline in CSS?

You could use border-top-left-radius and border-top-right-radius properties to round the corners on the box according to the box's height (and added borders). Then add a border to top/right/left sides of the box to achieve the effect.


2 Answers

You can use a pseudo-element to insert an absolutely-positioned border:

#status-buttons {
  position: relative;          /* 1 */
  display: inline-block;       /* 2 */
}
#status-buttons::after {       /* 3 */
  content: "";
  position: absolute;
  width: 50%;
  z-index: -1;                 /* 4 */
  top: 35%;
  left: 25%;
  border: 3px solid #ACCF5B;
}
#status-buttons a {
  color: black;
  display: inline-block;
  font-size: 17px;
  font-weight: normal;
  margin-right: 0;
  text-align: center;
  text-transform: uppercase;
  min-width: 150px;
  text-decoration: none;
}
#status-buttons a:hover {
  text-decoration: none;
}
#status-buttons a.active span {
  color: white;
  background: #ACCF5B;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
#status-buttons span {
  color: white;
  background: #22bacb;
  display: block;
  height: 45px;
  margin: 0 auto 10px;
  padding-top: 20px;
  width: 60px;
  border-radius: 50%;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
<div id="status-buttons" class="text-center">
  <a href="#/form/regalo" class="active"><span>1</span> Step 1</a>
  <a href="#/form/tusdatos"><span>2</span> Step 2</a>
</div>

Notes:

  1. Establish nearest positioned ancestor for absolute positioning.
  2. Make container consume only the width necessary.
  3. Insert pseudo element
  4. Ensure that any horizontal line overlap doesn't appear above circles
like image 152
Michael Benjamin Avatar answered Sep 20 '22 18:09

Michael Benjamin


You can add a new element and position it between the two circles:

#status-buttons a {
    color: black;
    display: inline-block;
    font-size: 17px;
    font-weight: normal;
    margin-right: 0;
    text-align: center;
    text-transform: uppercase;
    min-width: 150px;
    text-decoration: none;
}

#status-buttons a:hover {
  text-decoration: none;
}
    
#status-buttons a.active span {
    color: white;
    background: #ACCF5B;
    box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}

#status-buttons span {
    color: white;
    background: #22bacb;
    display: block;
    height: 45px;
    margin: 0 auto 10px;
    padding-top: 20px;
    width: 60px;
    border-radius: 50%;
    box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}

#line {
  position: absolute;
  top: 42px;
  left: 112px;
  width: 96px;
  height: 5px;
  background: #ACCF5B;
}
<div id="status-buttons" class="text-center">
                <a href="#/form/regalo" class="active"><span>1</span> Step 1</a>
                <div id="line">
                </div>
                <a href="#/form/tusdatos"><span>2</span> Step 2</a>
            </div>
like image 24
Dekel Avatar answered Sep 20 '22 18:09

Dekel