Hi I have a problem with my CSS I have used this rule before but somehow it's not working this time
I am trying to make a list that has a border on the bottom of every list item but the last. I have the following code:
.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
}
<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>
The :last-of-type selector allows you to target the last occurence of an element within its container. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content. ).
How to select an element that is the first or last child of its parent. The :first-child pseudo class means "if this element is the first child of its parent". :last-child means "if this element is the last child of its parent". Note that only element nodes (HTML tags) count, these pseudo-classes ignore text nodes.
If you have this 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
}
Then you are correctly removing the border from the last li
. However any link or div inside that li
will still have a bottom border.
So you need to remove that with:
.menu li:last-child a,
.menu li:last child div {
border-bottom: none
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With