I’m developing a website for a client, the design calls for some long vertical lines that sort of “connect” various elements (although they aren’t attached).
I’m trying to think of the best way of doing this.
On the surface level something like this would work:
But it’s not responsive at all. I need something that will line up with a title at at the top of the page, and stay lined up with a div much further down the page.
I like the simplicity of it, but I’m not sure how it would be responsive. For example if I had markup like:
<div class="container">
<div class="first-box"> Variable content length</div>
<div class="other-content"></div>
<p> Some other elements for good measure</p>
<div class="second-box">More content</div>
</div>
If I wanted to have the SVG go from .first-box to .second-box. How would it know the correct length if we were on mobile where the page might be 300% vs a desktop where the page would only be 100% or 120%?
Would the container element act as a bounding box between the first and second boxes? In other words, if the SVG line was centered inside container, would that give you the right result where it would go from the top of the container to the bottom of the container?
Both boxes have the same parent (parent expands to content) AND the boxes are first and last child
OR there is one element between the 2 boxes (put image as child of the element between and use position: absolute)
OR all the elements between the boxes have the same height that can be calculated
This is why we need display: sub-grid
You could put all the elements between the boxes in a wrapper BUT still have them use the wrapper’s parent auto-flow and use the wrapper for the size and position of the line.
display: contents doesn’t work because it removes the box entirely from the wrapper unfortunately…
For the first time in a while its Chrome that is late to the party on a critical feature.
Even Safari is doing it…
Thanks @steve and @kirupa, I’m a bit tardy in the response. I like @kirupa’s solution it’s elegant but the layout of the page is a variable number sections and divs. Something like:
<div class="container">
<section class="subsection">
<div class="content">
<!-- This is the start of the line -->
<div class="line"></div>
<span> Some amount of content / images... etc </span>
</div>
</section>
<section class="subsection">Another Section in a variable number of sections</section>
<section class="subsection">
<div class="content">
<h2>Hi</h2>
<div class="box">
The top of this box may be where the line should connect too?
</div>
</div>
</section>
</div>
From what I can tell I’d have to use @steve.mills 's JS approach here.
2 Likes
Creating engaging and entertaining content for designers and developers since 1998.