In this pen , I have created tree structure using some ul li tag
Created
January 12, 2020 23:23
-
-
Save CodeMyUI/471d3a7cbb743cdc67ec153b9717d355 to your computer and use it in GitHub Desktop.
Tree (Folder) structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Tree Structure using ul li</h3> | |
<ul class="treeRoot"> | |
<li class="hasSubMenu"><span>Root</span> | |
<ul class="activeSubMenu"> | |
<li class="hasSubMenu"><span>Branch1</span> | |
<ul> | |
<li><span>Branch1-sub2</span></li> | |
<li><span>Branch1-sub3</span></li> | |
<li><span>Branch1-sub4</span></li> | |
<li><span>Branch1-sub5</span></li> | |
<li><span>Branch1-sub6</span></li> | |
</ul> | |
</li> | |
<li><span>Branch2</span></li> | |
<li class="hasSubMenu"><span>Branch3</span> | |
<ul> | |
<li><span>Branch3-sub1</span></li> | |
<li class="hasSubMenu"><span>Branch3-sub2</span> | |
<ul> | |
<li><span>Branch3-sub1</span></li> | |
<li><span>Branch3-sub2</span></li> | |
<li><span>Branch3-sub3</span></li> | |
<li><span>Branch3-sub4</span></li> | |
<li><span>Branch3-sub5</span></li> | |
<li><span>Branch3-sub6</span></li> | |
</ul> | |
</li> | |
<li><span>Branch3-sub3</span></li> | |
<li><span>Branch3-sub4</span></li> | |
<li><span>Branch3-sub5</span></li> | |
<li><span>Branch3-sub6</span></li> | |
</ul> | |
</li> | |
</ul> | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("ul.treeRoot li span").on("click",function(){ | |
if($(this).parent().hasClass("hasSubMenu")){ | |
if($(this).parent().find("ul").hasClass("activeSubMenu")){ | |
$(this).parent().find("ul").removeClass("activeSubMenu"); | |
}else{ $(this).parent().find("ul").addClass("activeSubMenu"); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ul , li { | |
list-style: none; | |
margin: 0; | |
padding:0; | |
} | |
ul.treeRoot > li ul, | |
ul.treeRoot > li ul { | |
padding-left:20px; | |
} | |
ul.treeRoot li{ | |
border-left: 1px solid #000; | |
} | |
ul.treeRoot ul li, | |
ul.treeRoot li{ | |
border-left:1px solid #000; | |
padding-left: 20px; | |
position: relative; | |
font-size: 16px; | |
line-height: 24px; | |
} | |
ul.treeRoot ul li:last-child:after, | |
ul.treeRoot li:last-child:after{ | |
position:absolute; | |
content: ""; | |
display:inline-block; | |
top: 12px; | |
width:1px; | |
left: -1px; | |
bottom: 0; | |
background: #fff | |
} | |
ul.treeRoot ul li:before, | |
ul.treeRoot li:before{ | |
height: 1px; | |
background: #000; | |
width: 15px; | |
left:0; | |
top: 11px; | |
display: inline-block; | |
content: ""; | |
position: absolute; | |
} | |
.treeRoot li ul { | |
display: none; | |
} | |
.treeRoot li ul.activeSubMenu{ | |
display: block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment