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

5

2 Answers

Codepen

Give this a go:

html

<div></div> 

css

div { width: 200px; height: 200px; border: red 1px solid; position: relative; } div:after { content: ''; position: absolute; border-right: 2px green solid; height: 200px; width: 200px; transform: translateX(-50%); } div:before { content: ''; position: absolute; border-bottom: 2px green solid; height: 200px; width: 200px; transform: translateY(-50%); } 
4

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; } 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy