Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS brainteaser: How do alter last class result in a list [duplicate]

Tags:

css

I am displaying search results in a div:

<div id="results">
  <div class="list-item">[Text]</div>
  <div class="list-item">[Text]</div>
  <div class="list-item">[Text]</div>
  <div class="list-item">[Text]</div>
  <div class="list-item">[Text]</div>
  <div class="list-item">[Text]</div>
</div>

The number of list-items is variable. I want to have border-bottom: 1px solid #000; on all the list-item classes, except for the last result. Is there a way in CSS to do this, or do I need to use JS?

like image 728
alias51 Avatar asked Nov 24 '25 08:11

alias51


1 Answers

Use :not and :last-child:

.list-item:not(:last-child) {
  border-bottom:1px solid #000;
}

It works and its elegant: http://jsfiddle.net/3Znbu/

like image 85
Ivan Chernykh Avatar answered Nov 25 '25 20:11

Ivan Chernykh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!