JSFiddle - React, Tailwind, and code Playground
HTML
<!-- We will create a family tree using just CSS(3) The markup will be simple nested lists -->
<div class="tree">
<ul>
<li> <a href="#">Parent</a><span></span>
<ul>
<li><a href="#">Child</a>
<span></span>
<ul>
<li><a href="#">Grand Child</a><span></span>
</li>
</ul>
</li>
<li > <a href="#">Child</a><span></span>
<ul>
<li><a href="#">Grand Child</a><span></span>
</li>
<li><a href="#">Grand Child</a><span></span>
</li>
<li ><a href="#">Grand Child</a><span></span>
<ul>
<li><a href="#">Great Grand Child</a><span></span>
</li>
<li><a href="#">Great Grand Child</a><span></span>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Child</a>
<span></span>
<ul>
<li><a href="#">Grand Child</a><span></span>
</li>
</ul>
</li>
<li> <a href="#">Child</a><span></span>
<ul>
<li><a href="#">Grand Child</a><span></span>
</li>
<li><a href="#">Grand Child</a><span></span>
</li>
<li><a href="#">Grand Child</a><span></span>
<ul>
<li><a href="#">Great Grand Child</a><span></span>
</li>
<li><a href="#">Great Grand Child</a><span></span>
...
CSS
.tree ul {
position: relative;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
.tree li {
list-style-type: none;
left: 5%;
position: relative;
padding: 10px 5px 0 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
.tree li > span {
content:'';
position: absolute;
top: 0;
width: 3%;
height: 50px;
right: auto;
left: -2.5%;
border-bottom: 1px solid #ccc;
border-left: 1px solid #ccc;
border-radius: 0 0 0 5px;
-webkit-border-radius: 0 0 0 5px;
-moz-border-radius: 0 0 0 5px;
}
.tree li a {
border: 1px solid #ccc;
padding: 5px 10px;
text-decoration: none;
color: #666;
font-family: arial, verdana, tahoma;
font-size: 11px;
display: inline-block;
width: 180px;
height: 90px;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.tree li a:hover, .tree li a:hover+ul li a {
background: #c8e4f8;
color: #000;
border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.tree li a:hover+ul li::after, .tree li a:hover+ul li::before, .tree li a:hover+ul::before, .tree li a:hover+ul ul::before {
border-color: #94a0b4;
}
JavaScript
$('.tree li > span').each(function () {
var thisNewTop = $(this).closest('ul').offset().top - $(this).offset().top;
var thisNewHeight = $(this).offset().top - $(this).closest('ul').offset().top + 50;
$(this).css({
top: thisNewTop,
height: thisNewHeight
})
})