gpt4 book ai didi

html - 嵌套的 li 元素没有正确对齐

转载 作者:太空宇宙 更新时间:2023-11-03 23:13:48 25 4
gpt4 key购买 nike

我能够内联显示所有嵌套的li's。我不明白的是为什么 AboutOur Team li 元素之间存在差距。我已经尝试将 ulli 元素的 marginpadding 设置为 0.

<div ng-show = "buttonDisplay" id = "buttonDisplayContent">
<ul>
<li><a href = "#"> Home </a></li>
<li class = "subLi"><a href = "#"> About </a></li>
<ul class = "nested">
<li> <a href = "#"> Our Team </a> </li>
<li> <a href = "#"> Our efforts </a> </li>
</ul>
<li class = "nextToNested"><a href = "#"> Blog </a></li>
<li class = "subLi"><a href = "#"> Services </a></li>
<ul class = "nested">
<li> <a href = "#"> Design </a> </li>
<li> <a href = "#"> Web </a> </li>
<li> <a href = "#"> Learn </a> </li>
<li> <a href = "#"> Invent </a> </li>
</ul>
<li class = "nextToNested"><a href = "#"> Portfolio </a></li>
<li><a href = "#"> Contact </a></li>
</ul>
</div>

CSS

#buttonDisplayContent ul {
list-style-type: none;
padding: 0;
}

#buttonDisplayContent ul ul {
list-style-type: none;
padding: 0;
}

#buttonDisplayContent ul a {
text-decoration: none;
color: #000;
font-size: 25px;
font-weight: bold;
}

#buttonDisplayContent ul ul a {
text-decoration: none;
color: lightgray;
font-size: 15px;
font-weight: bold;
}

.subLi {
float: left;
margin: 0;
padding: 0;
list-style-type: none;
}

.nested {
margin-left: 0;
}

.nested li {
display: inline-block;
padding-bottom: 6px;
padding-right: 1%;
padding-left: 1%;
padding-top: 8px;
}

#buttonDisplayContent ul li:hover {
background-color: black;
}

更新

感谢您的帮助。我按如下方式更改了 HTMLCSSLi 元素仍未按要求对齐。这是一个 fiddle :https://jsfiddle.net/qvq87ke1/2/

HTML

<div ng-show = "buttonDisplay" id = "buttonDisplayContent" >
<ul>
<li><a href = "#"> Home </a></li>
<li class = "subLi"><a href = "#">About </a>
<ul class = "nested">
<li> <a href = "#"> Our Team </a> </li>
<li> <a href = "#"> Our efforts </a> </li>
</ul>
</li>
<li class = "nextToNested"><a href = "#"> Blog </a></li>
<li class = "subLi"><a href = "#"> Services </a>
<ul class = "nested">
<li> <a href = "#"> Design </a> </li>
<li> <a href = "#"> Web </a> </li>
<li> <a href = "#"> Learn </a> </li>
<li> <a href = "#"> Invent </a> </li>
</ul>
</li>
<li class = "nextToNested"><a href = "#"> Portfolio </a></li>
<li><a href = "#"> Contact </a></li>
</ul>
</div>

CSS

#buttonDisplayContent {
background-color: #141516;
width: 100%;
margin-top: 9%;
text-align: center;
position: absolute;
opacity: 0.9;
}

#buttonDisplayContent ul {
list-style-type: none;
padding: 0;
}

#buttonDisplayContent ul ul {
list-style-type: none;
padding: 0;
}

#buttonDisplayContent ul a {
text-decoration: none;
color: #fff;
font-size: 50px;
font-weight: bold;
}

#buttonDisplayContent ul ul a {
text-decoration: none;
color: lightgray;
font-size: 40px;
font-weight: bold;
}

.subLi {
float: left;
margin: 0;
padding: 0;
list-style-type: none;
}

.nested {
float: right;
margin-left: 0;
}

.nested li {
display: inline-block;
padding-bottom: 6px;
padding-right: 1%;
padding-left: 1%;
padding-top: 8px;
}

#buttonDisplayContent ul li:hover {
background-color: black;
}

最佳答案

您的标记看起来不正确。当嵌套无序或有序列表时,它们应该包含在 li 中,它们将为其创建子列表。

像这样:

<ul>
<li>One</li>
<li>Two
<ul>
<li>One - Sub Two</li>
<li>Two - Sub Two</li>
</ul>
</li>
<li>Three</li>
</ul>

您正在 li 之间添加您的 ul:

<li class="subLi"><a href="#">About</a></li>
<ul class="nested">
<li><a href="#">Our Team</a></li>
<li><a href="#">Our efforts</a></li>
</ul>
<li class="nextToNested"><a href="#">Blog</a></li>

关于html - 嵌套的 li 元素没有正确对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543694/

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