shlogg · Early preview
Ankit Verma @ankitv4087

CSS :has() Parent Selector Example

CSS :has() selects elements based on their contents. li:has(> a.active) targets any list item containing an active link, turning it red.

li:has(> a.active) → Selects any li that directly contains an a element with the class "active".
The parent li will turn red if it has an active link inside it.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS :has() Example</title>
    <style>
        /* Change text color of <li> if it contains an <a> with class "active" */
        li:has(> a.active) { 
            color: red; 
            font-weight: bold;
        }
    </style>
</head>
<body>
    <h1>CSS :has() Parent Selector Examp...