Vicheanak Vicheanak - 2 months ago 9
CSS Question

How to get the last Element of CSS?

<ul class="blog-year">
<li><a href="http://my.link">2016</a><span class="year-seperator">|</span></li>
<li><a href="http://my.link">2015</a><span class="year-seperator">|</span></li>
<li><a href="http://my.link">2014</a><span class="year-seperator">|</span></li>
<li><a href="http://my.link">2013</a><span class="year-seperator">|</span></li>
</ul>


in my css:

.year-seperator:last-of-type{
display: none;
}


Then all the separator disappear. Why? How can I get the last element of that class? Or How can I hide it?

Answer

Because they are all at last of li. It's the last li element not last span element. It should look like this:

li:last-child .year-seperator {
    display: none;
}
Comments