:nth-child(n)
In this chapter you will learn:
Description
:nth-child(n)
selects elements that are the nth child.
The argument is the index of the element.
The indexes start at 1.
Example
<!DOCTYPE HTML> <!-- j ava2 s . c o m-->
<html>
<head>
<style type="text/css">
body > :nth-child(2) {
border: thin black solid;
padding: 4px;
}
</style>
</head>
<body>
<a href="http://java2s.com">Visit the java2s.com</a>
<p>I like <span>HTML</span> and CSS.</p>
<a href="http://java2s.com">Visit the java2s.com</a>
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- Definition for Selector:nth-last-child(n)
- An example showing how to use :nth-last-child(n) CSS selector
Home » HTML CSS Tutorial » CSS Selector Reference