Using a formula (an + b) in nth-last-child(), n is a counter starting at 0, and b is an offset value. - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-last-child

Introduction

The following code shows how to select p elements whose index is a multiple of 3, counting from the last child.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:nth-last-child(3n+0) {
    background: red;
}
</style><!--from   w ww . j  a  v a2 s . c  o m-->
</head>
<body>

<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
<p>The fifth paragraph.</p>
<p>The sixth paragraph.</p>
<p>The seventh paragraph.</p>
<p>The eight paragraph.</p>
<p>The ninth paragraph.</p>

</body>
</html>

Related Tutorials