CSS :nth-of-type() Selector
You are Here:
CSS :nth-of-type() Selector
Example
HTML Online Editor
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
p:nth-of-type(3){
color: red;
}
</style>
</head>
<body>
<h1>CSS :nth-of-type() Selector</h1>
<p>This is 1st paragraph child of its parent (body).</p>
<div>
This is div
</div>
<p>This is 2nd paragraph child of its parent (body).</p>
<p>This is 3rd paragraph child of its parent (body).</p>
</body>
</html>
Syntax
Using CSS
:nth-of-type(number) {
color: red;
}
More Examples
Example
HTML Online Editor
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
p:nth-of-type(odd){
color: red;
}
p:nth-of-type(even){
color: blue;
}
</style>
</head>
<body>
<h1>CSS :nth-of-type() Selector</h1>
<p>This is 1st paragraph child of its parent (body).</p>
<div>
This is div
</div>
<p>This is 2nd paragraph child of its parent (body).</p>
<p>This is 3rd paragraph child of its parent (body).</p>
<div>
This is div
</div>
<p>This is 4th paragraph child of its parent (body).</p>
</body>
</html>
Example
HTML Online Editor
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
p:nth-of-type(3n+0){
color: red;
}
</style>
</head>
<body>
<h1>CSS :nth-of-type() Selector</h1>
<p>This is 1th paragraph child of its parent (body).</p>
<p>This is 2nd paragraph child of its parent (body).</p>
<p>This is 3rd paragraph child of its parent (body).</p>
<p>This is 4th paragraph child of its parent (body).</p>
<div>
This is Div
</div>
<p>This is 5th paragraph child of its parent (body).</p>
<p>This is 6th paragraph child of its parent (body).</p>
</body>
</html>
Reminder
Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in CSS.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.