SYNTAX
<style>
element:first-of-type {
/* styles */
}
</style>
Example :
<!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:first-of-type {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Welcome to RAYS Coding</h1>
<div class="paragraphs">
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the third paragraph.</p>
</div>
</body>
</html>
2. :last-of-type
SYNTAX
<style>
element:last-of-type {
/* styles */
}
</style>
Example :
<!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:last-of-type {
color: royalblue;
font-weight: bold;
font-family: sans-serif;
font-size: 50px;
}
</style>
</head>
<body>
<h1>Welcome to RAYS Coding</h1>
<div class="paragraphs">
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the third paragraph.</p>
</div>
</body>
</html>
SYNTAX
<style>
element:empty {
/* styles */
}
</style>
Example
<!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-class :empty</title>
<style>
body {
background: #1b1b1b;
color: white;
}
div:empty {
display: none;
}
</style>
</head>
<body>
<h1>Welcome to RAYS Coding</h1>
<div class="paragraphs">
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the third paragraph.</p>
</div>
<div class="empty"></div>
<h1>Welcome to RAYS Coding</h1>
</body>
</html>
SYNTAX
<style>
element:not(selector) {
/* styles */
}
</style>
Example
<!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-class Example</title>
<style>
body {
background: #1b1b1b;
color: white;
}
p:not(.highlight) {
color: green;
font-size: 40px;
font-family: sans-serif;
}
.highlight {
color: red;
}
</style>
</head>
<body>
<h1>Welcome to RAYS Coding</h1>
<p>This is a normal paragraph.</p>
<p class="highlight">This paragraph is highlighted!</p>
<p>This is another normal paragraph.</p>
</body>
</html>