Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add vertical line between two divs

Tags:

css

I want to make a vertical line between two divs. we have hr for horizontal line but none for vertical line as I know. Is there anyway to make it without using border?

<style>
#wrapper_1 {
    background-color:pink;
    height:100px;
    float:left;
    width: 100px;
}

#wrapper_2 {
    background-color:brown;
    height:100px;
    width: 100px;
    float:right;
}
</style>

<div id="wrapper_1">
    Creating slideshows PHP
</div> 

<div id="wrapper_2">
    Creating slideshows with WordPress 
</div>
like image 310
graxia Avatar asked Mar 16 '16 07:03

graxia


People also ask

How to add a horizontal line between two DIVS in HTML?

There are two ways to add a horizontal line between two divs. First, put a tag between the two divs, and the second is to place any block-level element such as a div, p, etc, between the two divs and apply a bottom or top border on it. Either way, you can achieve the same task.

How do I convert a line to a vertical?

You can use <hr>, as it is semantically correct, and then use CSS to convert it to a vertical line. hr.vertical { height:100%; /* you might need some positioning for this to work, see other questions about 100% height */ width:0; border:1px solid black; }

How can I horizontally align my divs?

Task #2: Set a linear gradient background for the div element, going from the top left to the bottom right, transitioning from "white" to "green" Install and run react js project...

How do you put a border between two DIVS in HTML?

First, put a tag between the two divs, and the second is to place any block-level element such as a div, p, etc, between the two divs and apply a bottom or top border on it. Either way, you can achieve the same task.


1 Answers

You can also use pseudo elements to make a vertical separator. You don't need an extra div to make a separator just use the pseudo elements and style it according to your needs.

#wrapper_1 {
  background-color: pink;
  height: 100px;
  float: left;
  width: 100px;
}
#wrapper_1:after {
  content: "";
  background-color: #000;
  position: absolute;
  width: 5px;
  height: 100px;
  top: 10px;
  left: 50%;
  display: block;
}
#wrapper_2 {
  background-color: brown;
  height: 100px;
  width: 100px;
  float: right;
}
<div id="wrapper_1">
  Creating slideshows PHP
</div>

<div id="wrapper_2">
  Creating slideshows with WordPress
</div>

PS: Beware of the absolute positioning of the pseudo elements. Thanks.

like image 154
vikrantnegi Avatar answered Sep 28 '22 03:09

vikrantnegi