CSS: Prevent parent element getting :active pseudoclass when child element is clicked

后端 未结 12 936
暖寄归人
暖寄归人 2021-01-07 16:19

JSFiddle

When you click the button, you see that :active pseudoclass is triggered for the parent div. Is ther

12条回答
  •  长情又很酷
    2021-01-07 16:57

    From the spec:

    Selectors doesn't define if the parent of an element that is ‘:active’ or ‘:hover’ is also in that state.

    That means it's implementation dependent. If an implementation chose to act this way (as current browsers obviously do), there's nothing in the standard that can change that.

    With CSS4, you might be able to do:

    .parent:active:not(:has(:active)) {
       color: red;
    }
    

    but that is neither available nor finalized yet.

提交回复
热议问题