CSS伪元素上的事件监听器,例如:: after和:: before?
问题描述:
我有一个 div
元素,其中CSS伪元素 :: before
用作关闭按钮(而不是使用实际按钮)。如何将事件监听器仅应用于 伪元素?
I have a div
element with a CSS pseudo-element ::before
used as a close button (instead of using an actual button). How do I apply an event listener to only the pseudo-element?
HTML
<div id="box"></div>
CSS
#box:before
{
background-image: url(close.png);
content: '';
display: block;
height: 20px;
position: absolute;
top: -10px;
right: -10px;
width: 20px;
}
#box
{
height: 100px;
width: 100px;
}
答
不。 DOM中不存在伪元素,因此它没有表示它的 HTMLElementNode
对象。
No. The pseudo-element does not exist in the DOM so it has no HTMLElementNode
object representing it.