How To Connect A Child Item In A Tree-structure Visualization With Css
I want to create a list of items and sub items that are connected with lines. So far I have done this - As you can see, Sub Task 3 is not fully connected with its parent. How to
Solution 1:
I would do it differently like below:
.main {
overflow: hidden;
}
ul {
list-style: none;
padding: 0;
margin-left: 30px;
margin-top: 10px;
}
.item {
position: relative;
line-height: 1.2em;
}
.item::before,
.item::after,
.item:last-child.sub-menu::before{
content: '';
background: #000;
position: absolute;
}
.item::before {
width: 10px;
height: 1px;
top: 0.5em;
left: -10px;
}
.item::after {
left: 20px;
bottom: 0.6em;
top: 1.2em;
width: 1px;
}
/* the bekow will avoid the line to go down if there is no sub task (not transparent!)*/.item:last-child > .sub-menu::before {
top: calc(0.6em - 1px);
width: 6px;
bottom: 0;
background: #fff;
left: -12px;
z-index: 1;
}
<ulclass="main"><liclass="item">Task 1</li><liclass="item">Task 2
<ulclass="sub-menu"><liclass="item">Sub Task 1</li><liclass="item">Sub Task 2
<ulclass="sub-menu"><liclass="item">Sub Task 1</li><liclass="item">Sub Task 2</li></ul></li><liclass="item">Sub Task 3
<ulclass="sub-menu"><liclass="item">Sub Task 1</li><liclass="item">Sub Task 2
<ulclass="sub-menu"><liclass="item">Sub Task 1</li><liclass="item">Sub Task 2</li></ul></li><liclass="item">Sub Task 3</li><liclass="item">Sub Task 4</li></ul></li></ul></li><liclass="item">Task 3</li></ul>
Post a Comment for "How To Connect A Child Item In A Tree-structure Visualization With Css"