Ask a question about the click status style

1. Question:

parent element has .parent: active , which changes the background color when clicked. The effect that
wants to achieve is that if you click on a special child element, you don"t want to trigger the parent element to change the background color, but other elements will trigger normally. Could you tell me how to do that? Can pure css do that? The page structure and style of
demo is as follows:

<!DOCTYPE html>
<html>    
<head>
<meta charset="utf-8"> 
<title>(runoob.com)</title> 
<style> 
    .parent{
        height: 100px;
        background: -sharpccc;
    }
    .parent:active {
        background: -sharpaaa;
    }
    .no-active{
        height: 40px;
        width: 40px;
        background: -sharp219;
        color: -sharpfff;
    }
</style>
</head>
<body>

    <div class="parent">
        <div class="no-acitve">hello</div>
        <div class="other">active</div>
    </div>

</body>
</html>
Jun.16,2021

just add a judgment

if(!e.target.className === "class" ) {
    ...
}

CSS currently does not have a parent selector, but there are certain ways to simulate
css:

.

.parent {
    position: relative;
    height: 100px;
    z-index: 1;
}

.replace {
    width: 100%;
    height: 100px;
    background: -sharpccc;
    z-index: -1;
    position: absolute;
    left: 0;
    top: 0;
}

.other:active+.replace {
    background: -sharpaaa;
}

.replace:active {
    background: -sharpaaa;
}

dom: < div class= "parent" >

    <div class="no-acitve">hello</div>
    <div class="other">active</div>
    <div class="replace"></div>
</div>
For more information, please see Link description

.

if you want this special child element to be active without any reaction, you can try CSS:pointer-events
of course, pay attention to compatibility.

Menu