Insert CSS parent section counter for nested lists - html

I have a 2 level ul. I am using counter-reset, counter-increment, and content to insert a running counter. It works in that the content in the lis is numbering correctly.
I have and a link in the first level li, after its nested ul that I want to say "Add To Rule [number of parent li]".
Below is a minimum working example of what I am doing. In the a link, it is using the counter for the 2nd level ul/li.
What it outputs:
Rule 1
Rule 1.1...
Rule 1.2...
Rule 1.3...
Add To Rule 1.3
Rule 2
Rule 2.1...
Rule 2.2...
Rule 2.3...
Add To Rule 2.3
Rule 3
Rule 3.1...
Rule 3.2...
Rule 3.3...
Add To Rule 3.3
What I am trying achieve:
Rule 1
Rule 1.1...
Rule 1.2...
Rule 1.3...
Add To Rule 1
Rule 2
Rule 2.1...
Rule 2.2...
Rule 2.3...
Add To Rule 2
Rule 3
Rule 3.1...
Rule 3.2...
Rule 3.3...
Add To Rule 3
I can't figure out what I need to do to get my expected/wanted output.
ul
{
counter-reset: section;
}
li
{
counter-increment: section;
}
.ruleNumber::after
{
content: counters(section, ".");
}
a::after
{
content: counters(section, ".");
}
<ul>
<li>
<span class="ruleNumber">Rule </span>
<ul>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
</ul>
Add To Rule
</li>
<li>
<span class="ruleNumber">Rule </span>
<ul>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
</ul>
Add To Rule
</li>
<li>
<span class="ruleNumber">Rule </span>
<ul>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
</ul>
Add To Rule
</li>
</ul>

You might use two separate counters -- one for sections and one for items:
ul {
counter-reset: section;
}
ul ul {
counter-reset: item;
counter-increment: section;
}
li {
counter-increment: item;
}
.ruleNumber::after {
content: counters(item, ".");
}
a::after {
content: counters(section, ".");
}
<ul>
<li>
<span class="ruleNumber">Rule </span>
<ul>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
</ul>
Add To Rule
</li>
<li>
<span class="ruleNumber">Rule </span>
<ul>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
</ul>
Add To Rule
</li>
<li>
<span class="ruleNumber">Rule </span>
<ul>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
<li>
<span class="ruleNumber">Rule </span>
<div class="rule">...</div>
</li>
</ul>
Add To Rule
</li>
</ul>

Related

display list that in each row 1 li

How can I display the list that in each line I will have one li and not 2 li in one row?
<div class="recent_questions promoted_questions pblock">
<ul class="vertical_menu main_questions">
<li>
<span class="header">
corona<img src="photos/Covid.gif"></span>
<span class="questions"><span class="big_image">
<img class="photo_sub" src="photos/covid.jpg"/></span></span>
</li>
<li></li>
<li></li>
</ul>
</div>
You can simply wrap your images into individual <li> elements, and they will appear below each other:
<div class="recent_questions promoted_questions pblock">
<ul class="vertical_menu main_questions">
<li>
<span class="header">
<a href="covid.php">
corona
<img src="photos/Covid.gif">
</a>
</span>
</li>
<li>
<span class="questions">
<span class="big_image">
<img class="photo_sub" src="photos/covid.jpg" />
</span>
</span>
</li>
</ul>
</div>

Jquery filter - html elements

How to filter html elements using Jquery function ?
Below is the html structure. I want to get the value of 2nd span which is inside a tag warpped in a li item ?
<li>
<a href="Link2">
<span class="message">Item2</span>
<span class="icon">Icon_2</span>
</a>
</li>
<li>
<a href="Link3">
<span class="message">Item3</span>
<span class="icon">Icon_3</span> ----- **How to filter and find this element value based on the message span value ?
</a>
</li>
```````````````
I need a condition like in li if span's value = "Item3", get the below span.icon's value
Couple of ways to do it. One way is with has and contains.
$("li:has(span.icon:contains('Icon_3'))").addClass("selected")
.selected {
background-color: lime;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>
<a href="Link2">
<span class="message">Item2</span>
<span class="icon">Icon_2</span>
</a>
</li>
<li>
<a href="Link3">
<span class="message">Item3</span>
<span class="icon">Icon_3</span>
</a>
</li>
</ul>
And now based on the information you provided.....
var text = $("span.message:contains(Item3) + span.icon").text()
console.log(text);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>
<a href="Link2">
<span class="message">Item2</span>
<span class="icon">Icon_2</span>
</a>
</li>
<li>
<a href="Link3">
<span class="message">Item3</span>
<span class="icon">Icon_3</span>
</a>
</li>
</ul>
or how most people would do it.
var messageElem = $("span.message").filter(function(){ return this.textContent === "Item3" });
var text = messageElem.next("span.icon").text();
console.log(text);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>
<a href="Link2">
<span class="message">Item2</span>
<span class="icon">Icon_2</span>
</a>
</li>
<li>
<a href="Link3">
<span class="message">Item3</span>
<span class="icon">Icon_3</span>
</a>
</li>
</ul>
I'd prefer this, because :contains() seeks the matching string and not exact string. That is why, using filter is better :)
var choice = $("li span.message").filter(function(){
return $(this).text().trim() === "Item3";
}).next('span.icon');
//If there is only one item with text "Item3"
console.log(choice.text());
//If there are multiple items
choice.each(function(){
console.log($(this).text());
});
.selected {
background-color: lime;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>
<a href="Link2">
<span class="message">Item2</span>
<span class="icon">Icon_2</span>
</a>
</li>
<li>
<a href="Link3">
<span class="message">Item3</span>
<span class="icon">Icon_3</span>
</a>
</li>
</ul>
Code:
$('li span.icon')
It should work

Reduce spacing between booststrap list-inline elements

I'm using bootstrap list-inline class to style my breadcrumbs but I don't like the spacing between the elements. How do I reduce the spacing between John, Jane and David ?
Here's how it currently looks
<ul class="list-inline">
<li>
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.google.com" itemprop="url">
<span itemprop="title">John</span>
</a> >
</div>
</li>
<li>
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="www.yahoo.com" itemprop="url">
<span itemprop="title">Jane</span>
</a> >
</div>
</li>
<li>
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="www.msn.com" itemprop="url">
<span itemprop="title">David</span>
</a>
</div>
</ul>
</li>
You can override the base css and add a negative margin to the li elements like so:
.list-inline>li {
margin-right: -10px;
}
Run the below code snippet to see what this produces.
.list-inline>li {
margin-right: -10px;
}
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<ul class="list-inline">
<li>
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.google.com" itemprop="url">
<span itemprop="title">John</span>
</a> >
</div>
</li>
<li>
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="www.yahoo.com" itemprop="url">
<span itemprop="title">Jane</span>
</a> >
</div>
</li>
<li>
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="www.msn.com" itemprop="url">
<span itemprop="title">David</span>
</a>
</div>
</li>
</ul>
One of the options is to remove the padding from elements with css.
.no-left-gutter{padding-left:0;}
And add this class to li or a elements.
<li class="no-left-gutter">
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.google.com" itemprop="url" class=no-left-gutter>
<span itemprop="title">John</span>
</a>
</div>
</li>
can be fixed by funky code formatting...
<ul class="list-inline">
<li>
List Item One</li><li>
List Item Two</li><li>
List Item Three</li>
</ul>
can be fixed by adding html comments...
<ul class="list-inline">
<li>List Item One</li><!--
--><li>List Item Two</li><!--
--><li>List Item Three</li>
</ul>

Proper align li elements on a row

I want to create my own calendar using css ul's and li's. Most calendars I have seen on the web use this way better than a table(don't know why is that). I have created some basic layout of the calendar, but seem to have a problem with aligning the day titles on top of the calendar. I am new to css so please be gentle with me. I know I could get one ready, but I like learning by doing and asking. So here is my code and the jsfiddle
<div id="calendar-month">
<ul class="title">
<div class="days-title">
<li>Mon</li>
<li>Tue</li>
<li>Wen</li>
<li>Thu</li>
<li>Fri</li>
<li>Sat</li>
<li>Sun</li>
</div>
</ul>
<div class="days">
<ul class="days-item">
<li></li>
<li></li>
<li></li>
<li></li>
<li>
<span class="day-label">1</span>
</li>
<li>
<span class="day-label">2</span>
</li>
<li>
<span class="day-label">3</span>
</li>
<li>
<span class="day-label">4</span>
</li>
<li>
<span class="day-label">5</span>
</li>
<li>
<span class="day-label">6</span>
</li>
<li>
<span class="day-label">7</span>
</li>
<li>
<span class="day-label">8</span>
</li>
<li>
<span class="day-label">9</span>
</li>
<li>
<span class="day-label">10</span>
</li>
<li>
<span class="day-label">11</span>
</li>
<li>
<span class="day-label">12</span>
</li>
<li>
<span class="day-label">13</span>
</li>
<li>
<span class="day-label">14</span>
</li>
<li>
<span class="day-label">15</span>
</li>
<li>
<span class="day-label">16</span>
</li>
<li>
<span class="day-label">17</span>
</li>
<li>
<span class="day-label">18</span>
</li>
<li>
<span class="day-label">19</span>
</li>
<li>
<span class="day-label">20</span>
</li>
<li>
<span class="day-label">21</span>
</li>
<li>
<span class="day-label">22</span>
</li>
<li>
<span class="day-label">23</span>
</li>
<li>
<span class="day-label">24</span>
</li>
<li>
<span class="day-label">25</span>
</li>
<li>
<span class="day-label">26</span>
</li>
<li>
<span class="day-label">27</span>
</li>
<li>
<span class="day-label">28</span>
</li>
<li>
<span class="day-label">29</span>
</li>
<li>
<span class="day-label">30</span>
</li>
<li>
<span class="day-label"></span>
</li>
</ul>
</div>
</div>
and the css
* {
margin:0px;
padding: 0px;
}
#calendar-month{
margin:auto;
width: 600px;
height: 480px;
background-color:#C2CCD1
}
.title {
margin:auto;
}
.title .days-title li{
list-style: none;
display: inline-block;
padding-left:0.5em;
padding-right:0.5em;
}
.days{
margin:auto;
width:600px;
height:475px;
}
#calendar-month .days-item li{
list-style: none;
display:inline-block;
float: left;
width:70px;
height:86px;
background-color:white;
border:1px solid black;
margin-left:4px;
padding-left:8px;
margin-bottom:2px;
}
.day-label{
float:right;
padding-right: 7px;
padding-top: 2px;
}
It migth not be the right way, maybe you could offer me a better way to understand paddings and margins or how to group them more properly. No it's not homework or anything else :), just getting inot design small step at a time :)
It's because you haven't applied the same properties to .title .days-title li as you have #calendar-month .days-item li. Specifically, width, padding and margin.
Add these to .title .days-title li:
width: 70px;
margin-left: 4px;
padding-left: 8px;
WORKING FIDDLE
If your days have a fixed width of 70px, why not add the CSS:
.days-title li{
width:64px;
text-align:center;
}
Fiddle

Representing folder hierarchy with html

I'm building a web application that will show a hierarchy of things. The hierarchy will closely resemble that of a file system with folders and files, i.e. I'll have folders that contains files and subfolders in any depth level (though it will probably never go deeper than three levels).
The whole hierarchy will be shown in one view. It will be shown in a tree style and the folders can be expanded/closed by the user at will. The diffrent levels are indented, just as a standard file system browser.
What is a good way of representing this with HTML and CSS? Note that it is not the design/look itself I need help with but rather how to structure this in a good way using HTML. Should I use lists?
An approach framed using div and span, explained below with a working example at last.
Every folder contains 2 types of contents. Files and inner Folders. So a basic structure is designed with a overall container.
Overall Container:
<div id="hierarchy">
<!--folder structure goes here-->
</div>
Folder Structure:
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 1</span>
<span class="file fa-file-excel-o">File 11</span>
<span class="file fa-file-code-o">File 12</span>
<span class="file fa-file-pdf-o">File 13</span>
</div>
Folder Structure (with no files):
<div class="foldercontainer">
<span class="folder fa-folder">Folder 1</span>
<span class='noitems'>No Items</span>
</div>
The foldercontainer contains span elements that specifies the file names. First span element contains the folder title, while the remaining contains the filenames. The data- attribute isexpanded specifies whether the specified folder is expanded or collapsed.
If a folder contains no files, then add the noitems span element to the structure.
While a folder contains another folder, just add the same html as a child to it. i.e.,
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 1</span>
<span class="file fa-file-excel-o">File 11</span>
<span class="file fa-file-code-o">File 12</span>
<span class="file fa-file-pdf-o">File 13</span>
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 1-1</span>
<span class="file fa-file-excel-o">File 1-11</span>
<span class="file fa-file-code-o">File 1-12</span>
<span class="file fa-file-pdf-o">File 1-13</span>
</div>
</div>
Javascript:
The click event is delegated from the parent #hierarchy element to the folders and files, to handle click in a single event listener. On clicking a folder, it is expanded and the icon changes. On clicking again it collapses and resets the icon.
While the inner folder is expanded and outer folder is collapsed, when expanding the outer folder, the inner folder contents states are preserved, by design.
Refer this nice article to learn how to handle events on multiple elements in a single listener.
Note: The code can be altered to make use of CSS custom variables and Data attributes access to CSS to be more efficient, while the former is not supported in IE and latter has its own disadvantages in cross-browser support. So use at your own risk.
Working example with various hierarchies:
var hierarchy = document.getElementById("hierarchy");
hierarchy.addEventListener("click", function(event){
var elem = event.target;
if(elem.tagName.toLowerCase() == "span" && elem !== event.currentTarget)
{
var type = elem.classList.contains("folder") ? "folder" : "file";
if(type=="file")
{
alert("File accessed");
}
if(type=="folder")
{
var isexpanded = elem.dataset.isexpanded=="true";
if(isexpanded)
{
elem.classList.remove("fa-folder-o");
elem.classList.add("fa-folder");
}
else
{
elem.classList.remove("fa-folder");
elem.classList.add("fa-folder-o");
}
elem.dataset.isexpanded = !isexpanded;
var toggleelems = [].slice.call(elem.parentElement.children);
var classnames = "file,foldercontainer,noitems".split(",");
toggleelems.forEach(function(element){
if(classnames.some(function(val){return element.classList.contains(val);}))
element.style.display = isexpanded ? "none":"block";
});
}
}
});
#hierarchy
{
font-family: FontAwesome;
width: 300px;
}
.foldercontainer, .file, .noitems
{
display: block;
padding: 5px 5px 5px 50px;
}
.folder
{
color: red;
}
.file
{
color: green;
}
.folder, .file
{
cursor: pointer;
}
.noitems
{
display: none;
pointer-events: none;
}
.folder:hover,.file:hover
{
background: yellow;
}
.folder:before, .file:before
{
padding-right: 10px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="hierarchy">
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 1</span>
<span class="file fa-file-excel-o">File 11</span>
<span class="file fa-file-code-o">File 12</span>
<span class="file fa-file-pdf-o">File 13</span>
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 1-1</span>
<span class="file fa-file-excel-o">File 1-11</span>
<span class="file fa-file-code-o">File 1-12</span>
<span class="file fa-file-pdf-o">File 1-13</span>
</div>
<div class="foldercontainer">
<span class="folder fa-folder">Folder 1-2</span>
<span class='noitems'>No Items</span>
</div>
<div class="foldercontainer">
<span class="folder fa-folder">Folder 1-3</span>
<span class='noitems'>No Items</span>
</div>
<div class="foldercontainer">
<span class="folder fa-folder">Folder 1-4</span>
<span class='noitems'>No Items</span>
</div>
</div>
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 2</span>
<span class="file fa-file-excel-o">File 21</span>
<span class="file fa-file-code-o">File 22</span>
<span class="file fa-file-pdf-o">File 23</span>
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 2-1</span>
<span class="file fa-file-excel-o">File 2-11</span>
<span class="file fa-file-code-o">File 2-12</span>
<span class="file fa-file-pdf-o">File 2-13</span>
<div class="foldercontainer">
<span class="folder fa-folder">Folder 2-1-1</span>
<span class='noitems'>No Items</span>
</div>
</div>
</div>
<div class="foldercontainer">
<span class="folder fa-folder-o" data-isexpanded="true">Folder 3</span>
<span class="file fa-file-excel-o">File 31</span>
<span class="file fa-file-code-o">File 32</span>
<span class="file fa-file-pdf-o">File 33</span>
<div class="foldercontainer">
<span class="folder fa-folder">Folder 3-1</span>
<span class='noitems'>No Items</span>
</div>
</div>
</div>
The good way to represent it in HTML is to organize your file list as a... HTML list :) For example you might get this:
<ul>
<li>Folder 1
<ul>
<li>SubFile 1</li>
<li>SubFile 2</li>
<li>SubFile 3</li>
</ul></li>
<li>Folder 2
<ul>
<li>SubFile 4</li>
<li>SubFile 5</li>
<li>SubFile 6</li>
</ul></li>
<li>Main File 1</li>
<li>Main File 2</li>
</ul>
Then the CSS can be very soft, because the list already represents a hierarchy.
I would avoid <ul> since that's for an "un-ordered list" whereas your folder structure will likely be in some sort of order.
I'd use the Definition List, or Ordered List;
<dl>
<dt>Folder 1
<dl>
<dt>Child 1</dt>
<dt>Child 2</dt>
<dt>Child 3</dt>
</dl>
</dt>
<dt>Folder 2
<dl>
<dt>Child 1</dt>
<dt>Child 2</dt>
<dt>Child 3</dt>
</dl>
</dt>
</dl>
<ol>
<li>Folder 1
<ol>
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3</li>
</ol>
</li>
<li>Folder 2
<ol>
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3</li>
</ol>
</li>
</ol>
I have created folder hierarchy using list items. This will help for sure.
$(function() {
setFolderHeirarchy();
});
function setFolderHeirarchy() {
var labelWrapper= $('.labelWrapper');
$(labelWrapper).each(function () {
if (!$(this).next('.subFolderHeirarchy')||$(this).next('.subFolderHeirarchy').length==0) {
$(this).find('.arrow').remove();
}
else{
console.log($(this).next('.subFolderHeirarchy'));
}
});
$('.labelWrapper').click(function() {
if ($(this).next('.subFolderHeirarchy').length > 0) {
$(this).parent('.folderHeirarchyList').toggleClass('active');
if ($(this).parent('.folderHeirarchyList').hasClass('active')) {
$(this).find('.arrow').removeClass('glyphicon-triangle-right').addClass('glyphicon-triangle-bottom');
} else {
$(this).find('.arrow').removeClass('glyphicon-triangle-bottom').addClass('glyphicon-triangle-right');
}
}else{
// $(this).css('color','red');
}
});
}
.mainFolderHeirarchy li {
border: none;
background: 0 0!important
}
.mainFolderHeirarchy li a {
color: #000;
text-decoration: none!important
}
.mainFolderHeirarchy li a:hover {
text-decoration: none!important
}
.mainFolderHeirarchy .folderHeirarchyList {
padding-top: 3px;
padding-bottom: 3px
}
.mainFolderHeirarchy .folderHeirarchyList.active>.subFolderHeirarchy {
display: block
}
.mainFolderHeirarchy .folderHeirarchyList .subFolderHeirarchy {
display: none;
padding-left: 5px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<h1> Folder Heirarchy/ multi level list item</h1>
<hr />
<ul class="list-group mainFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
<ul class="subFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
<ul class="subFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
<ul class="subFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
<ul class="subFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
<ul class="subFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
<ul class="subFolderHeirarchy">
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
</ul>
</li>
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="list-group-item folderHeirarchyList">
<span class="arrow glyphicon glyphicon-triangle-right"></span><span class="listlabel">listitem</span>
</li>
</ul>
</li>
</ul>
You can create a file tree with this html format:
<div class="cont">
<ul class="tree">
<li>
<div class="div"><i class="folder"></i> Folder</div>
<ul class="branch">
<li><i class="file"></i> File 1</li>
<li><i class="file"></i> File 2</li>
</ul>
</li>
</ul>
</div>
And with css and JavaScript:
var toggler = document.getElementsByClassName("div");
var i;
var slct = "None"
for (i = 0; i < toggler.length; i++) {
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".branch").classList.toggle("active");
});
toggler[i].addEventListener("click", function() {
slct = this.textContent
document.getElementById("slct").textContent = slct
})
}
var files = document.getElementsByClassName("file")
for (i = 0; i < files.length; i++) {
files[i].parentNode.addEventListener("click", function() {
slct = this.textContent
document.getElementById("slct").textContent = slct
})
}
.tree {
list-style-type: none;
text-align: left;
padding: 0;
padding: 4px;
}
.active {
display: block !important;
}
.branch {
list-style-type: none;
display: none;
}
.folder {
height: 0px;
width: 0px;
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48IS0tISBGb250IEF3ZXNvbWUgUHJvIDYuMS4xIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlIChDb21tZXJjaWFsIExpY2Vuc2UpIENvcHlyaWdodCAyMDIyIEZvbnRpY29ucywgSW5jLiAtLT48cGF0aCBkPSJNNTEyIDE0NHYyODhjMCAyNi41LTIxLjUgNDgtNDggNDhoLTQxNkMyMS41IDQ4MCAwIDQ1OC41IDAgNDMydi0zNTJDMCA1My41IDIxLjUgMzIgNDggMzJoMTYwbDY0IDY0aDE5MkM0OTAuNSA5NiA1MTIgMTE3LjUgNTEyIDE0NHoiLz48L3N2Zz4=);
background-repeat: no-repeat;
overflow: clip;
padding: 8px;
text-align: center;
background-position: center;
position: relative;
filter: invert(74%) sepia(99%) saturate(730%) hue-rotate(357deg) brightness(100%) contrast(104%);
}
.file {
height: 0px;
width: 0px;
background-repeat: no-repeat;
overflow: clip;
padding: 6px;
text-align: center;
background-position: center;
position: relative;
filter: invert(74%) sepia(99%) saturate(730%) hue-rotate(357deg) brightness(100%) contrast(104%);
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzODQgNTEyIj48IS0tISBGb250IEF3ZXNvbWUgUHJvIDYuMS4xIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlIChDb21tZXJjaWFsIExpY2Vuc2UpIENvcHlyaWdodCAyMDIyIEZvbnRpY29ucywgSW5jLiAtLT48cGF0aCBkPSJNMCA2NEMwIDI4LjY1IDI4LjY1IDAgNjQgMEgyMjRWMTI4QzIyNCAxNDUuNyAyMzguMyAxNjAgMjU2IDE2MEgzODRWNDQ4QzM4NCA0ODMuMyAzNTUuMyA1MTIgMzIwIDUxMkg2NEMyOC42NSA1MTIgMCA0ODMuMyAwIDQ0OFY2NHpNMjU2IDEyOFYwTDM4NCAxMjhIMjU2eiIvPjwvc3ZnPg==);
}
.cont {
width: 100%;
border-style: solid;
background-color: #dea002;
}
<div class="cont">
<ul class="tree">
<li>
<div class="div"><i class="folder"></i> Hello</div>
<ul class="branch">
<li class="item"><i class="file"></i> Hi</li>
<li>
<div class="div"><i class="folder"></i> Folder</div>
<ul class="branch">
<li><i class="file"></i> File 1</li>
<li><i class="file"></i> File 2</li>
</ul>
</li>
</ul>
</li>
<li><i class="file"></i> World</li>
</ul>
</div>
<b>Selceted File: <code id="slct">None</code></b>
This format is comprehensive and is not glitchy and unusable.
Note: The html above is a more extensive version of the first example.
I would use a table. The different columns represent deeper levels of indentation.