I am looking to create a responsive tree diagram, here is a basic example: https://jsfiddle.net/ppnfpggx/2/
However, I am facing some challenges with the responsive layout. Particularly on smaller devices, it should appear like this:https://i.sstatic.net/5JFYJ.png
Above each item:
.tree-item::after {
content: '';
position: absolute;
top: -15px;
left: -20px;
height: 4px;
background-color: #000;
width: 88px; // (48 + 20 + 20 -> half-margin on both sides)
}
Since the number of items may vary, I have experimented with :last-child
to remove ::before
, but encountered issues with the item before the last one. My goal is to have the third item act as the closing point for the tree, removing pseudo-elements
from the remaining items and somehow centering the last two items without using margin-left
.
Is it possible to achieve this responsive layout using CSS/JS? If so, could you please provide any ideas or a basic example?