SYNTAX
<style>
element:nth-last-of-type() {
/* styles */
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RAYS Coding: Pseudo-classes</title>
<style>
body {
background: #1b1b1b;
color: white;
}
P:nth-last-of-type(2) {
color: blueviolet;
font-size: 40px;
font-family: sans-serif;
}
</style>
</head>
<body>
<div>
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Third Paragraph</p>
<p>Fourth Paragraph</p>
<p>Fifth Paragraph</p>
</div>
</body>
</html>
2. :nth-of-type()
SYNTAX
<style>
<style>element:nth-of-type() {
/* styles */
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RAYS Coding: Pseudo-classes</title>
<style>
body {
background: #1b1b1b;
color: white;
}
P:nth-of-type(2) {
color: blueviolet;
font-size: 40px;
font-family: sans-serif;
}
</style>
</head>
<body>
<div>
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Third Paragraph</p>
<p>Fourth Paragraph</p>
<p>Fifth Paragraph</p>
</div>
</body>
</html>
3. :only-child()
SYNTAX
<style>
element:only-child {
/* styling properties */
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RAYS Coding: Pseudo-classes</title>
<style>
body {
background: #1b1b1b;
color: white;
}
p:only-child {
color: red;
font-family: sans-serif;
font-size: 40px;
}
</style>
</head>
<body>
<div>
<p>This is the only child</p>
</div>
<div>
<p>This is one child</p>
<p>This is another child</p>
</div>
</body>
</html>
SYNTAX
<style>
element:only-of-type {
/* Styles yaha likhein */
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RAYS Coding: Pseudo-classes</title>
<style>
body {
background: #1b1b1b;
color: white;
}
p:only-of-type {
color: royalblue;
font-family: sans-serif;
font-size: 40px;
}
</style>
</head>
<body>
<div>
<p>This is the only paragraph.</p>
<span>This is a span.</span>
</div>
<div>
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
</div>
</body>
</html>