Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical Line with Branches in css

Tags:

html

jquery

css

I trying to draw a vertical line with multiple branches left and right sides of the line. I used pseudo class div after but when right side text there is a problem in positioning the arrow.Is there any other way to write this class.Can anyone suggest me how to write this class?

Any help appreciated. enter image description here for inspiration look at this demo

.at-timeline .timeline--details {
  position: relative;
}
.at-timeline .timeline--single {
    display: flex;
    flex-direction: row;
}
.at-timeline .timeline--details,
.at-timeline .time--date {
    flex-basis: 14%;
    padding: 15px 50px;
}
.text-right { text-align: right;}
.at-timeline .timeline--details:before {
  content: "";
  position: absolute;
  width: 35px;
  height: 2px;
  top: 17%;
  right: 0;
  background: #2783e8;
}
.at-timeline:after {
  content: "";
  position: absolute;
  width: 2px;
  height: 300%;
  top: 15%;
  left: 24%;
  background: #2783e8;
}
<div class="timeline at-timeline" style="padding: 100px;">
	<div class="timeline--single">
		<div class="timeline--details text-right">
			<h4 class="timeline--title">Title</h4>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non dolor ultricies, porttitor justo non, pretium mi.</p>
		</div>
		<span class="time--date">
			<span class="date">01</span>
			<span class="month">January</span>
			<span class="year">2017</span>
		</span>
	</div>
	<div class="timeline--single">
		<span class="time--date text-right">
			<span class="date">01</span>
			<span class="month">January</span>
			<span class="year">2017</span>
		</span>
		<div class="timeline--details reverse">
			<h4 class="timeline--title">Title</h4>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non dolor ultricies, porttitor justo non, pretium mi.</p>
		</div>
	</div>
	<div class="timeline--single">
		<div class="timeline--details text-right">
			<h4 class="timeline--title">Title</h4>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non dolor ultricies, porttitor justo non, pretium mi.</p>
		</div>
		<span class="time--date">
			<span class="date">01</span>
			<span class="month">January</span>
			<span class="year">2017</span>
		</span>
	</div>
</div>
like image 929
Husna Avatar asked Dec 22 '17 07:12

Husna


People also ask

How do you add a vertical line in CSS?

You can use the horizontal rule tag to create vertical lines. By using minimal width and large size, horizontal rule becomes a vertical one.

How do I put a vertical line between two divs?

You can use margin property to make space between two div. To give to space between two divs, just add display: flex in the parent element. If you're adding space for lines of text then use line-height. If adding space between paragraphs then apply top or bottom margin or padding.

How do I make my HR tag vertical?

The <hr> tag in HTML is used to produce a horizontal line. However, there is no tag for creating a vertical line. The border-left CSS attribute can be used to simulate a vertical line. The border-left property of CSS is used to style the left-side border.

How do I draw a vertical line in the center of a div?

Use the div named “v1” and put the “border-left” property. This property helps in drawing a vertical line inside the div container. The “width” of the vertical line is “10px”. This line appears in “solid” type because we set “solid” as the type of the border property.


1 Answers

You could accomplish it using absolute positioning and a bunch of margins and paddings like in this snippet

.at-timeline {
  position: relative;
  width: 70%;
}

.at-timeline:after {
  content: "";
  position: absolute;
  width: 2px;
  height: 900px;
  top: 0;
  left: 50%;
  background: #2783e8;
}
.timeline--single {
  position: relative;
  margin: 50px 0;
}
.timeline--single:nth-child(odd) .timeline--details {
  margin-right: 50%;
  text-align: right;
  padding-right: 50px;
}

.timeline--single:nth-child(odd) .time--date{
  position: absolute;
  left: 50%;
  top: 0px;
  margin-left: 20px;
}
.timeline--single:nth-child(even) .time--date{ 
  position: absolute;
  right: 50%;
  top: 0px;
  margin-right: 20px;
}

.timeline--single:nth-child(even) .timeline--details {
  margin-left: 50%;
  text-align: left;
  padding-left: 50px;
}

.at-timeline .timeline--details:before {
  content: "";
  position: absolute;
  width: 35px;
  height: 2px;
  top: 10px;
  background: #2783e8;
}

.timeline--single:nth-child(odd) .timeline--details:before { 
  right: 50%;
}
.timeline--single:nth-child(even) .timeline--details:before { 
  left: 50%;
}

.timeline--title {
  margin-top: 5px;
}
<div class="timeline at-timeline" style="padding: 100px;">
	<div class="timeline--single">
		<div class="timeline--details text-right">
			<h4 class="timeline--title">Title</h4>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non dolor ultricies, porttitor justo non, pretium mi.</p>
		</div>
		<span class="time--date">
			<span class="date">01</span>
			<span class="month">January</span>
			<span class="year">2017</span>
		</span>
	</div>
	<div class="timeline--single">
		<span class="time--date text-right">
			<span class="date">01</span>
			<span class="month">January</span>
			<span class="year">2017</span>
		</span>
		<div class="timeline--details reverse">
			<h4 class="timeline--title">Title</h4>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non dolor ultricies, porttitor justo non, pretium mi.</p>
		</div>
	</div>
	<div class="timeline--single">
		<div class="timeline--details text-right">
			<h4 class="timeline--title">Title</h4>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non dolor ultricies, porttitor justo non, pretium mi.</p>
		</div>
		<span class="time--date">
			<span class="date">01</span>
			<span class="month">January</span>
			<span class="year">2017</span>
		</span>
	</div>
</div>
like image 170
JoshKisb Avatar answered Sep 25 '22 20:09

JoshKisb