Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert vertical divider line between two nested divs, not full height

I have float left and float right <div> nested within a light blue box div as shown in the image below. I can't figure out how to insert a vertical line between them as shown in this image:

enter image description here

That has the following properties:

1) padding/margin on either side that I can control or looks reasonable (i.e. not much closer to one div than it is the other)

2) leaves a margin above and below as shown, i.e. does not extend the full vertical width of light blue div

3) dynamically maintains #1 and #2 as browser window gets bigger/smaller and blue box size increases/decreases with it

I'm looking for a simple, preferably CSS-only solution.

Relevant CSS:

#left {   position: relative;   float: left;   width: 44%;   margin: 0;   padding: 0; }  #right {   position: relative;   float: right;   width: 49%;   margin: 0;   padding: 0; }  #blue_box {   position: relative;   width: 45%;   min-width: 400px;   max-width: 600px;   padding: 2%;   margin-left: 40%;   overflow: auto; /*needed so that div stretches with child divs*/ } 
like image 376
Tim Koelkebeck Avatar asked Mar 19 '11 21:03

Tim Koelkebeck


People also ask

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

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 you make a horizontal separator line in HTML?

The <hr> tag in HTML stands for horizontal rule and is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The <hr> tag is an empty tag, and it does not require an end tag. Used to specify the alignment of the horizontal rule.

What is a vertical divider in CSS?

Additionally, a CSS divider is normally worked to be adjustable and utilize innovative thoughts and hues to make your content stand apart effectively. So today in this article, we will discuss some examples of vertical divider/line also known as section dividers or separator with the help of HTML and CSS.

How to create dividers in HTML?

How To Create Dividers Step 1) Add HTML: Example <hr class="dashed"> <hr class="dotted"> <hr class="solid"> <hr class="rounded"> Step 2) Add CSS: Example /* Dashed border */ hr.dashed { border-top: 3px dashed #bbb; /* Dotted border */ hr.dotted {

How do I stretch the divider module vertically?

To stretch the Divider Module vertically, we’re going to add ‘480px’ to the top and bottom custom padding of our Divider Module. Et voilà, we have our vertical divider!

How many vertical divider do I need for my website?

You get 4 vertical divider (You can include a greater amount of them). The white background works very well with plain and clean light themed website.Or you could also zest it up by utilizing differentiating shading designs for that additional wow factor. 7. Vertical Separator with HTML and CSS


1 Answers

Use a div for your divider. It will always be centered vertically regardless to whether left and right divs are equal in height. You can reuse it anywhere on your site.

.divider{     position:absolute;     left:50%;     top:10%;     bottom:10%;     border-left:1px solid white; } 

Check working example at http://jsfiddle.net/gtKBs/

like image 78
Hussein Avatar answered Sep 28 '22 05:09

Hussein