Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting vertical lines between CSS elements that are part of a table's rows

Tags:

css

I'd like to connect some CSS circles with a vertical line between them.

I've attempted to use the pseudo-element :after selector as follows:

.circle {
  height: 45px;
  width: 45px;
  border-radius: 50%;
  border: 2px solid;
  position: relative;
  border-color: #889EB7;
}

.circle:before {
  content: "";
  display: block;
  position: absolute;
  z-index: 1;
  left: 18px;
  top: 0;
  bottom: 0;
  border: 1px dotted;
  border-width: 0 0 0 1px;
}

But I'm not getting any result at all.

Photo for reference of what I'd like to accomplish:

enter image description here

like image 576
Richard Kho Avatar asked Aug 13 '15 09:08

Richard Kho


People also ask

How do I insert a vertical line between two divs?

You can use <hr> , as it is semantically correct, and then use CSS to convert it to a vertical line.

How do I add a vertical line to a table in CSS?

To make a vertical line, use border-left or border-right property. The height property is used to set the height of border (vertical line) element. Position property is used to set the position of vertical line. Example 1: It creates a vertical line using border-left, height and position property.

How do I make my HR tag vertical?

If you use flexbox as rows (display: flex; flex-direction: row;) hr elements will automatically become vertical. You just need to set it's height property (e.g. height: 80%;).


2 Answers

Use the :before pseudo element this way:

* {font-family: 'Segoe UI'; font-size: 10pt;}
.circle {position: relative; border: 2px solid #999; border-radius: 100%; width: 50px; line-height: 50px; text-align: center; margin-top: 50px; background-color: #fff; z-index: 2;}
.circle:first-child {margin-top: 0;}
.circle:before {position: absolute; border: 1px solid #999; width: 0; height: 50px; display: block; content: ''; left: 50%; z-index: 1; top: -54px; margin-left: -1px;}
.circle:first-child:before {display: none;}
<div class="circle">Step 1</div>
<div class="circle">Step 2</div>
<div class="circle">Step 3</div>
like image 131
Praveen Kumar Purushothaman Avatar answered Sep 19 '22 16:09

Praveen Kumar Purushothaman


You do have to give your :before element a width and a height if you want ti to appear as a line. Have a look at this:

.circle {
  height: 45px;
  width: 45px;
  border-radius: 50%;
  border: 2px solid;
  position: relative;
  border-color: #889EB7;
}

.circle:before {
  content: "";
  display: block;
  position: absolute;
  z-index: 1;
  top: 100%;
  left: 50%;
  border: 1px dotted;
  border-width: 0 0 0 1px;
  width: 1px;
  height: 100px;
}
<div class='circle'></div>
like image 21
somethinghere Avatar answered Sep 19 '22 16:09

somethinghere