gpt4 book ai didi

html - CSS 中的层次结构显示

转载 作者:行者123 更新时间:2023-11-27 23:38:39 25 4
gpt4 key购买 nike

我在为分层显示(如文件和文件夹树)设计 CSS 时遇到了问题。我使用嵌套的无序列表:

<ul>
<li>animals<ul>
<li>dogs</li>
<li>cats</li>
</ul></li>
</ul>

它们在适当的 CSS 减去连接线的情况下可以很好地显示。我需要连接线。我使用以下 CSS 执行此操作:

ul ul li:before {
content: "";
padding: 15px;
border: 1px solid #000;
border-width: 0 0 1px 1px;
border-radius: 0 0 0 10px;
position: absolute;
left: -22px;
top: -15px;
}

问题是线条与动物、狗和猫的图标重叠。我尝试更改 z-index 无效。有没有更好的方法可以用 CSS 实现这一点?还是有其他方法让 z-index 有意义?

最佳答案

查看此示例。您可以轻松地用图像替换鲑鱼色框:

file structure with css example

HTML

<div>
<h3>Root</h3>
<ul>
<li>Folder 1
<ul>
<li>Folder 2
<ul>
<li>file1.xml</li>
<li>file2.xml</li>
<li>file3.xml</li>
</ul>
</li>
<li>file.html</li>
</ul>
</li>
<li>file.psd</li>
<li>file.cpp</li>
</ul>
</div>

CSS

body {
margin: 20px;
line-height: 3;
font-family: sans-serif;

}

div {
position: relative;
}

ul {
text-indent: .5em;
border-left: .25em solid gray;
}

ul ul {
margin-top: -1.25em;
margin-left: 1em;

}

li {
position: relative;
bottom: -1.25em;
}

li:before {
content: "";
display: inline-block;
width: 2em;
height: 0;
position: relative;
left: -.75em;
border-top: .25em solid gray;
}

ul ul:before, h3:before, li:after {
content: '';
display: block;
width: 1em;
height: 1em;
position: absolute;
background: salmon;
border: .25em solid white;
top: 1em;
left: .4em;
}

h3 {
position: absolute;
top: -1em;
left: 1.75em;
}

h3:before {
left: -2.25em;
top: .5em;
}

Demo

关于html - CSS 中的层次结构显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57126273/

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