Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a border in the middle of the div (horizontally)?

Tags:

css

border

less

I have a line of objects/elements like this:

enter image description here

I want to create a line, and place it behind all my objects, in the center if my div.

Here is what I'm hoping to make:

enter image description here

To create a border on top, right, bottom, left, or around a div is quite simple, but in the middle of the div is surprisingly hard. I've been trying to research on this, but I don't see any good one so far.

Any CSS expert want to show off your CSS skill?

Fiddle

like image 411
code-8 Avatar asked Mar 27 '15 01:03

code-8


People also ask

How do you center a div in the middle of the page?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do you border a div in HTML?

You can use: border-style: solid; border-width: thin; border-color: #FFFFFF; You can change these as you see fit, though.

How do I make a horizontal line in CSS?

Its simple to add a horizontal line in your markup, just add: <hr>. Browsers draw a line across the entire width of the container, which can be the entire body or a child element.


1 Answers

Here is your own updated JSFiddle

.border-center { 
            width: 100%;
            border: red 1px solid;
            position: relative;
        }

.border-center:before { content: '';
        position: absolute;
        bottom: 50%;
        border-bottom: 2px green solid;
        width: 100%;
        z-index:0;
    }
like image 199
Brett East Avatar answered Oct 16 '22 06:10

Brett East