CSS Lines would be a new type of CSS pseudo elements and matching properties that allow you to connect 2 or more elements with lines. The line ends always stay anchored to their corresponding elements and fit fluidly.
-
Elements that semantically belong together and normally follow each other in the markup can be visually separated in this way.
-
Multiple modals can be opened without losing the visual reference.
-
Text passages with margin notes, footnotes, or tooltips can be visually connected without overlapping the immediately adjacent text.
-
Tabular content or lists can be broken up visually. This makes simple organizational charts possible..
-
For purely decorative purposes. Face it! 😁
Turn a nested list into an Organigram.
<h1>Some Cantons, cities, quarters</h1>
<ul>
<li>Graubünden
<ul>
<li>Chur</li>
<li>Lanquart</li>
<li>Pontresina</li>
</ul>
</li>
<li>Freiburg
<ul>
<li>Bulle</li>
<li>Düdingen</li>
<li>Gruyères</li>
</ul>
</li>
<li>St.Gallen
<ul>
<li>St.Gallen
<ul>
<li>St.Georgen</li>
<li>Notkersegg</li>
<li>Bruggen</li>
<li>Riethüsli</li>
<li>Rotmonten</li>
</ul>
</li>
<li>Rorschach</li>
<li>Altstätten</li>
<li>Unterwasser</li>
</ul>
</li>
</ul>
Footnotes oder footnote like content (tooltips, abbreviation explanations)
<article>
<p>… Gaart Fletschen déi Völkerbond <a href="#a" title="Read footnote">Gart no vun prächteg welle.</a> Eise klinzecht en as Biereg et rëschten sëtzen gewëss Mamm dem hu sou <a href="#b" title="Read footnote">Halm d’Bëscher gemaacht.</p>
<p>…</p>
<footer>
<h3>Footnotes</h3>
<p id="a">Spilt As iwer ze alles …</p>
<p id="b">Bléit Hämmel heescht …</p>
</footer>
</article>
To get the result of this image, the usage would look like this:
<a href="#b">A</a>
<p id="b">B</p>
a::line {
connection: attr(href);
border: 3px solid white;
}
a::anchor {
right: 1rem;
bottom: 1rem;
}
#b::anchor {
left: 1rem;
top: 1rem;
}
To get the result of this image, the usage would look like this:
<div class="a">A</div>
<div class="b">B</div>
.a::line {
connection: ".b";
border: 3px solid white;
}
.a::anchor {
right: 1rem;
bottom: 1rem;
}
.b::anchor {
left: 1rem;
top: 1rem;
}
<h1>Blah</h1>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
h1::line {
line-to: "& + ul li";
border: 3px solid white;
}
h1::anchor {
top: 50%;
right: 1rem;
& + ul li::anchor {
top: 1rem;
left: 1rem;
}
}
<div class="a">A</div>
<div class="b">B</div>
.a::line {
connection: ".b";
border: 3px solid white cubic-bezier(.5,0,1,.5);
}
.a::anchor,
.b::anchor {
left: 50%;
bottom: 1rem;
}
.b::anchor {
display: block;
width: 2rem;
height: 2rem;
border-radius: 100%;
background-color: white;
}
The construction of a line and its endings are done like lines in svg by default.
The positioning of the anchors would happen on the same point.
Based on this and with the same new pseudo element ::line
like above it could work like this:
<div class="a"></div>
<div class="b"></div>
.a {
anchor-name: --a
}
.b {
anchor-name: --b
}
.b::line {
border: 3px solid white;
position: absolute;
start-x: calc( anchor(--a right) + 2rem );
start-y: calc( anchor(--a bottom) + 2rem );
end-x: anchor(--b center);
end-y: anchor(--b center);
While this already works with block elements in a similar way in Chrome Canary’s with the flag «Experimental Web Platform features» enabled — here is a sample on code pen — it would need a slightly different way for line elements («2 corners only»).
The code above is the most obvious approximation. But since it is absurd to be able to set two start properties to different anchors, another solution is needed. Maybe like this:
.a {
anchor-name: a
}
.b {
anchor-name: b
}
.b::line {
border: 3px solid white;
position: absolute;
start-anchor: a( calc(100% - 1rem), 50% );
end-anchor: a(center);
One drawback, however, is that this becomes difficult with simple user-generated content, such as Markdown. The other is that the whole thing is not based on semantic relations.
After publishing my spontaneous idea, I had some very valuable conversations with @[email protected] and [email protected]. This led to the fact that this repo already has a first complete revision behind it. Many thanks for that.