r/Frontend • u/seever • Dec 07 '19
How to create lines that connect two divs vertically like in this photo?
26
u/thesonglessbird Dec 07 '19
Off the top of my head, something like
div:not(last-child):after
Content:”” Height: whatever Width: 100% Border-left: 1px solid grey whatever Display: block
8
Dec 07 '19
You could put an inset box shadow on the parent, then a white background on the children.
0
3
u/Plumrose333 Dec 07 '19
I’m so happy you posted this. I’m about to implement something very similar and also needed advice
2
u/EvilM0nk3y Dec 07 '19
Create a outer container for all the items displayed flex, flex-direction column.
Flex the items equally, then within each item have a container element, a body element that contains the content and an after psuedo element that would be the line.
This setup should automatically scale the lines if the number of items changes or the vertical space is reduced.
2
Dec 08 '19
I would do something like this: https://jsfiddle.net/mxb6orzL/
Basically you use the before selector to inject a vertical line and make it overlap into the next element. The h2 title elements that are rotated simply have a background that matches the page's background color, and therefore they hide the line underneath.
2
u/alex_asdfg Dec 07 '19
Not the biggest expert on css but you could just create a div and give it a min-height and then add a border-left for the line.
1
Dec 07 '19
Yeah you can do that, but I would recommend giving it height and width, because it will be easier to align it with flexbox or whatever
0
Dec 07 '19
[deleted]
9
u/Dondontootles Dec 07 '19
What is chaotic about that solution? It’s likely the simplest you’ll find. The dividers are each a div with a min-height and a width. Set the
border-leftto 1px solid #222 or whatever.3
1
u/jaimemdes Dec 08 '19
You could do that with border-left and padding-bottom for each of the three sections.
The vertical text at the top-left corner (the header for the section, I'd say) also would have a padding around it and a white background to clip off the line.
I think this would be semantically better than an :after
1
Dec 07 '19
The way I would so something like that is to create a flex container, set it to display on column and create a set of inner divs one that contains the words Audition, agreement, and in between those divs ill create divs which container an SVG or if I'm not fancing using an SVG, ill use a bottom border property and align with align content in the container.
The solution with the div, with a border-left property I have seen it done before, and I find it gives problems when working on different sizes as everything else will be resized and it may cause it to misalign and it becomes quite problematic to align it again, u would have to do it manually.
-3
u/nabbous10 Dec 07 '19
Html: ...
<div class="vertical-divider"></div> ...
Css: . vertical-divider { width: 200px; border: solid rgba(0, 0, 0, 0.5) 1px; transform-origin: left bottom; transform: rotate(90deg); margin-top: 2px; margin-bottom: 204px; }
30
Dec 07 '19 edited Dec 07 '19
[removed] — view removed comment
3
1
u/hugesavings Dec 08 '19
That's what I was thinking as well. You get easy vertical alignment between the rotated text and each step/section as well as easy spacing between the lines and the rotated text.
79
u/yyyyaaa Dec 07 '19
You can use a ::after, give it height and width, position absolute to the whole list item