CHAPTER 82
CSS Advanced Selectors
Learn powerful selector techniques for targeting elements precisely.
01. What is CSS Advanced Selectors?
Advanced selectors allow more precise styling without adding unnecessary classes.
Selectors can target attributes, relationships and element states.
Good selectors make CSS reusable and maintainable.
02. Syntax
/* Attribute */
input[type="email"] { }
/* Child */
.card > p { }
/* First child */
li:first-child { }
/* Nth child */
li:nth-child(2) { }
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
li:nth-child(odd) {
background: #eff6ff;
}
li:first-child {
font-weight: bold;
}
input[type="email"] {
border: 2px solid #2563eb;
}
</style>
</head>
<body>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
<input
type="email"
placeholder="Email"
>
</body>
</html>
04. Important Points
✓
Use selectors that clearly describe the target.
✓
Pseudo-classes can select elements by position or state.
✓
Attribute selectors are useful for forms.
✓
Avoid unnecessarily complex selectors.
05. Common Mistakes
⚠
Creating selectors that are too specific.
⚠
Using selectors that are difficult to understand.
⚠
Relying on document structure that may change.
06. Real World Use
Advanced selectors are useful for forms, menus, tables, cards and reusable UI components.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Practice Advanced Selectors
Style odd list items differently and target an email input using an attribute selector.