gpt4 book ai didi

html - HTML+CSS 树形表

转载 作者:行者123 更新时间:2023-11-28 17:43:57 27 4
gpt4 key购买 nike

偶然发现 TreeTable 的问题...帮助理解,勾选上面的td input时,如何让second level及再往下不出现。不幸的是我只能使用 HTML+CSS。 how it looks like now on jsfiddle

<table class="table-tree" cellspacing="0">
<tr>
<td>
<label for="folder2">Folder 1</label>
<input type="checkbox" id="folder2" />
<table class="table-wrapper">
<tr>
<td class="file"><a href="">Subfile 1</a></td>
<td class="file"><a href="">Subfile 2</a></td>
<td>
<label for="folder3">Subfolder 1</label>
<input type="checkbox" id="folder3" />
<table class="table-wrapper">
<tr>
<td class="file"><a href="">Subsubfile 1</a></td>
<td class="file"><a href="">Subsubfile 2</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

如果布局是这样就好了

enter image description here

有人能帮帮我吗?

最佳答案

您需要将 table 替换为 ul(或 ol),将 td 替换为 li(删除 tr)在 HTMLCSS 中,它看起来就像图像上的 disered 布局。

这样做的另一个原因是您显示的内容不是表格数据,它是一个文件列表,因此您不应该使用表格,而应该使用列表类型布局。

FIDDLE

HTML:

<ul class="table-tree" cellspacing="0">
<li>
<label for="folder2">Folder 1</label>
<input type="checkbox" id="folder2" />
<ul class="table-wrapper">
<li class="file"><a href="">Subfile 1</a>

</li>
<li class="file"><a href="">Subfile 2</a>

</li>
<li>
<label for="folder3">Subfolder 1</label>
<input type="checkbox" id="folder3" />
<ul class="table-wrapper">
<li class="file"><a href="">Subsubfile 1</a>

</li>
<li class="file"><a href="">Subsubfile 2</a>

</li>
</ul>
</li>
</ul>
</li>
</ul>

CSS:

*, html {
font-family: Verdana, Arial, Helvetica, sans-serif;
}
body, form, ul, li, p, h1, h2, h3, h4, h5 {
margin: 0;
padding: 0;
}
body {
background-color: #fafafa;
color: rgba(0, 0, 0, 0.7);
margin: 0;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/**
* Tree Table CSS
**/
.table-tree {
display: block;
padding: 30px 0 0 30px;
}
li {
display: block;
position: relative;
}
li label {
background: url(http://www.webmasters.by/images/articles/css-tree/folder-horizontal.png) 15px 1px no-repeat;
cursor: pointer;
display: block;
padding-left: 37px;
width: 100%;
}
li input {
position: absolute;
left: 0;
margin-left: 0;
opacity: 0;
z-index: 2;
cursor: pointer;
height: 1em;
width: 1em;
top: 0;
}
li input + ul {
background: url(http://www.webmasters.by/images/articles/css-tree/toggle-small-expand.png) -3px -1px no-repeat;
margin: -0.938em 0 0 0;
height: 1em;
width: 1em;
}
li input:checked + ul {
background: url(http://www.webmasters.by/images/articles/css-tree/toggle-small.png) 41px 4px no-repeat;
display: block;
margin: -1.25em 0 0 -44px;
padding: 1.25em 0 0 80px;
height: auto;
width: 100%;
}
li.file {
margin-left: -1px !important;
}
li input + ul > li {
display: none;
margin-left: -14px !important;
padding-left: 1px;
}
li input:checked + ul > li {
display: block;
margin: 0 0 0.125em;
}
li input:checked + ul > li:last-child {
margin: 0 0 0.063em;
/* 1px */
}

关于html - HTML+CSS 树形表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23627762/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com