Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vertical lines between list items using CSS?

Tags:

html

css

I am referring to these lines: http://prntscr.com/d44uuk I want them to have dynamic height - so if I decide to change vertical distance between <li> elements - they will resize automatically.

Here's my fiddle: https://jsfiddle.net/v6ccgkwo/

ul {
  list-style: none;
}

ul li {
  margin-bottom: 40px;
}

ul li span {
  border-radius: 50%;
  border: 1px dashed black;
  padding: 5px 10px;
  margin-right: 10px;
}
<ul>
  <li><span>1</span>Легко устанавливается на сайт</li>
  <li><span>2</span>Следит за поведением посетителей</li>
  <li><span>3</span>Замечает, когда они тянут курсор к крестику, намереваясь уйти</li>
  <li><span>4</span>И показывает всплывающее окно с заманчивым предложением</li>  
</ul>
like image 668
yaru Avatar asked Nov 07 '16 11:11

yaru


People also ask

How do I put a vertical line between text 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 you make a vertical divider in CSS?

Answer: Use the CSS border Property You can use the CSS border property on a <span> element in combination with the other CSS property like display and height property to make vertical lines in HTML.

How do I add vertical space between lists in HTML?

Complete HTML/CSS Course 2022 To create space between list bullets and text in HTML, use CSS padding property. Left padding padding-left is to be added to <ul> tag list item i.e. <li> tag. Through this, padding gets added, which will create space between list bullets and text in HTML.


2 Answers

This will work with dynamic content and no extra DOM has been used. Give a try

ul {
  list-style: none;
}

ul li {
  padding-bottom: 40px;
  position:relative
}

ul li span {
  border-radius: 50%;
  border: 1px dashed black;
  padding: 5px 10px;
  margin-right: 10px;
  background:#fff
}
ul li span:before{
  content:'';
  position:absolute;
  border-left:1px solid ;
  left:14px;
  bottom:0;
  z-index:-1;
  height:100%
}

ul li:last-child span:before{
 content:none;
}
ul li:last-child{
  padding-bottom:0
}
<ul>
<li><span>1</span>Легко устанавливается на сайт</li>
<li><span>2</span>Следит за поведением посетителей</li>
<li><span>3</span>Замечает, когда они тянут курсор к крестику, намереваясь уйти</li>
<li><span>4</span>И показывает всплывающее окно с заманчивым предложением</li>
  </ul>
like image 76
Santhosh Kumar Avatar answered Oct 18 '22 04:10

Santhosh Kumar


Improved version with auto incremented counter that generates numbering

ul {
  max-width: 400px;
  margin: 0 auto;
  list-style-type: none;
  counter-reset: steps;
  margin: 0;
  font-family: sans-serif;
}
ul li {
  padding: 0 0 20px 50px;
  position: relative;
  margin: 0;
}
ul li:after {
  position: absolute;
  top: 0;
  left: 0;
  content: counter(steps);
  counter-increment: steps;
  border: 2px solid #000;
  border-radius: 50%;
  display: inline-block;
  height: 24px;
  width: 24px;
  text-align: center;
  line-height: 24px;
  background: #fff;
}
ul li:before {
  position: absolute;
  left: 13px;
  top: 0;
  content: "";
  height: 100%;
  width: 0;
  border-left: 2px dashed #000;
}
ul li:last-of-type:before {
  border: none;
}
<ul>
  <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
  <li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>
  <li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</li>
  <li>Et harum quidem rerum facilis est et expedita distinctio.</li>
</ul>
like image 34
stobasan Avatar answered Oct 18 '22 04:10

stobasan