TreeView or hierarchical data are typically gathered dynamically; my data are created via php on the server-side from database or eg. filesystem, and I needed something more structured, which gives me a chance to handle them via javascript on the client-side.
For me, a table
, with colspan
for variable indent worked.
To systematically handle similar cells in the same way (class attribute), I used to write out same count of TD on every TR, but made the unused ones display:none
- which gives the same index for a kind of nth-child(..)
formatting.
Missing are for example item-IDs per TR to link to the database for handling, and of course all of javascript.
The colors here in the example are used to easily find placing errors during testing.
screenshot FireFox Mint 104
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="webdev (at) kgsw (dot) de">
<meta name="description" content="2022-09-01/kg: Example hierarchical view (tree view)">
<meta name="keywords" content="html, html5, css, tree view, table">
<style>
body {
font-family: sans-serif;
}
table {
border-collapse:collapse;
cursor:default; }
td,th {
font-size:12px;
border:1px solid lightblue; /* transparent; */
line-height: normal;
padding: 0;
}
td { display:none; }
td.symbol, td.line, td.indent { display:table-cell; }
td.line { color:blue; }
td.symbol { color:green; }
td.indent { color:grey;font-size:8px; }
td:nth-child(12) { display:table-cell; width:70%; } /* items */
td:nth-child(13) { display:table-cell; min-width:80px; } /* remarks */
td:hover { background-color:#dec; }
td.line:hover { background-color:transparent; }
td.symbol:hover { color:red; }
</style></head><body>
<table>
<tr>
<td class="indent"> #</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="11"> <small>ROOT</small></td><td> :remarks</td>
</tr><tr>
<td class="indent"> 1</td><td class="line">├ </td><td class="symbol">▢</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="9"> Item1</td><td> </td>
</tr><tr>
<td class="indent"> 2</td><td class="line">│ </td><td class="line">├ </td><td class="symbol">▢ </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="8"> Item1.1</td><td> </td>
</tr><tr>
<td class="indent"> 3</td><td class="line">│ </td><td class="line">└ </td><td class="symbol">▢ </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="8"> Item1.2</td><td> </td>
</tr><tr>
<td class="indent"> 4</td><td class="line">├ </td><td class="symbol">▢</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="9"> Item2</td><td> </td>
</tr><tr>
<td class="indent"> 5</td><td class="line">├ </td><td class="symbol">▢</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="9"> Item3</td><td> </td>
</tr><tr>
<td class="indent"> 6</td><td class="line">└ </td><td class="symbol">▢</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td colspan="9"> Item4</td><td> </td>
</tr><tr>
</tr>
</table>
<hr>
<cite><p>changing generell class (display) to 'skip' and signing only used TDs to 'table-cell'</p>
</cite>
</body></html>
z-index
only works on elements that are position relative, absolute, or fixed. Make sure the thing you don't want to overlap is also relative or absolutely positioned. Also what do you mean by 'the lines to connect'. I also do not see any icons in your code. – Judeposition
attribute. Didn't include the CSS for the icons to simplify things, but they arebackground-image
's to theli
elements. Just checked, theli
element and the:before
element haveposition
s ofrelative
andabsolute
, respectively, but z-index still did not work. – Vannie