CSS伪元素上的事件监听器,例如:: after和:: before? [英] Event listener on a CSS pseudo-element, such as ::after and ::before?
本文介绍了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.
这篇关于CSS伪元素上的事件监听器,例如:: after和:: before?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文