Advanced Css
Advanced Css
Advanced
C S S
Selectors
SELECTOR
Page 1
CSS tips
1. :not( )
Description: Excludes elements that match a given selector.
Example:
<body>
<p class=”primary”> Welcome to My Website</p>
<p> This is a basic HTML document.</p>
</body>
Page 2
CSS tips
2. :nth-child()
Description: Selects elements based on their position within a parent.
Example:
<body>
<p> Welcome to My Website</p>
<p> This is a basic HTML document.</p>
<p> This is a basic HTML document.</p>
</body>
Page 3
CSS tips
3. :nth-of-type()
Description: Selects elements of a specific type based on their
position among siblings.
Example:
<body>
<p> Welcome to My Website</p>
<h2> This is a basic HTML document.</2>
<p> This is a basic HTML document.</p>
</body>
Page 4
CSS tips
4. :first-of-type, :last-of-type
Description: Selects the first or last element of a specific type among
siblings.
Example:
<body>
<p> Welcome to My Website</p>
<h2> This is a basic HTML document.</2>
<p> This is a basic HTML document.</p>
</body>
Page 5
CSS tips
5. :enabled, :disabled
Description: Selects form elements that are enabled or disabled.
Example:
<body>
<input type="text" />
<input type="text" disabled />
</body>
Page 6
CSS tips
6. :checked
Description: Selects elements that are checked (like radio buttons
or checkboxes).
Example:
<body>
<input type="checkbox" checked/>
<label>I agree</label>
</body>
Page 7
CSS tips
7. :focus-within
Description: Targets an element when any of its descendants are
focused.
Example:
<div>
<input type="text" />
<label>First Name :</label>
</div>
Page 8
CSS tips
8. ::selection
Description: Styles the portion of an element selected by the user.
Example:
<body>
<p> Welcome to My Website</p>
<p> This is a basic HTML document.</p>
</body>
Page 9
CSS tips
9. :has()
Description: Selects elements that contain other elements
matching a selector (browser support may vary).
Example:
<body>
<div>
<p>Nested paragraph</p>
</div>
<div>No paragraph here</div>
</body>
Page 10
CSS tips
10. :root
Description: Selects the root element of the document (usually
<html>). Commonly used to define global CSS variables.
Example:
Rendered Output:
The <p> text will appear in blue (#2ecc71)
Hint:
Use :root to define variables (--variable-
name) that act as global values, ensuring
consistency and easy maintenance across
your CSS.
You can access these variables anywhere
using the var() function.
Page 11
CSS tips
Page 12