Han*_*nah 4 html css parent-child html-lists
嗨,我的CSS有问题我之前使用过这条规则,但不知怎的,这次它不起作用
我试图创建一个列表,在每个列表项的底部有一个边框,但最后一个.我有以下代码:
.menu li {
border-bottom: .1rem solid #CCC;
padding: 0;
}
.menu li:last-child {
border: none;
}
.menu li a,
.menu li div {
display: block;
padding: .5rem 0rem .5rem;
border-bottom: .1rem solid #ccc
}Run Code Online (Sandbox Code Playgroud)
<div class="panel">
{% comment %}
{% endcomment %}
<h1>All {{team.abbrev}} {% trans "Songs" %}</h1>
{% for chant in chants %}
{% with chant.team as team %}
<ul class="menu">
<li>
<span>
<h6 style="margin-bottom:0;">
<a href="{% url 'chant' team.slug chant.slug %}">{{ forloop.counter}}) {{ chant.name }}</a>
</h6>
</span>
</li>
</ul>
{% if forloop.counter == 5 %}
{% include 'inc/adsense_listing.html' %}
{% endif %}
{% endwith %}
{% endfor %}
</div>Run Code Online (Sandbox Code Playgroud)
如果你有这个CSS
.menu li {
border-bottom: .1rem solid #CCC;
padding: 0;
}
.menu li:last-child {
border: none;
}
.menu li a,
.menu li div {
display: block;
padding: .5rem 0rem .5rem;
border-bottom: .1rem solid #ccc
}
Run Code Online (Sandbox Code Playgroud)
然后你正在从最后一个删除边框li.然而任何链接或格内认为li仍会有一个底部边框.
所以你需要删除它:
.menu li:last-child a,
.menu li:last child div {
border-bottom: none
}
Run Code Online (Sandbox Code Playgroud)
小智 0
最后一个子边框在您的情况下没有工作正常。但你已经写了风格
.menu li a,
.menu li div {
display: block;
padding: .5rem 0rem .5rem;
border-bottom: .1rem solid #ccc
}
Run Code Online (Sandbox Code Playgroud)
而是写两个不同的 css 规则:
.menu li a {
display: block;
padding: .5rem 0rem .5rem;
}
.menu li div {
display: block;
padding: .5rem 0rem .5rem;
border-bottom: .1rem solid #ccc
}
Run Code Online (Sandbox Code Playgroud)