我有以下标记:
<div class="parent">
I should change my color to green when clicked
<div class="element">I should do nothing when clicked</div>
</div>
这里是相关的CSS代码:
.parent {
width:200px;
height:200px;
background: red;
color: #fff;
}
.parent:active {
background:green;
}
.element {
background:blue;
}
有没有办法在点击
.element
时,防止触发.parent
的:active
伪类?尝试了在.element
被点击时使用e.stopPropogation()
,但没有成功。
演示
.stopPropagation()
方法对 CSS 渲染没有影响,只影响 JavaScript 事件。 - Linus Caldwell