CSS :nth-last-of-type

CSS :nth-last-of-type(an+b) pseudo class represent all sibling elements of same type whose sibling position is obtained by putting n=0,1,2,3… and so on counting from last.

CSS :nth-last-of-type values

The values are same as :nth-of-type. Only different is position counting starts from last.

Example – :nth-last-of-type

Change background of initial 2 siblings of type p counting from last

<style type="text/css" media="screen">
.box > p:nth-last-of-type(-n+2) {
  background-color:lightgreen;
}
</style>
<div class="box">
  <p>p1</p>
  <p>p2</p>
  <p>p3</p>
  <p>p4</p>
  <p>p5</p>
  <div>div1</div>
</div>
refresh

Related

Specification

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments