admin管理员组文章数量:1025206
Is there any way to use CSS pointer-events to apply only to the text e.g. in a div? This seems to work with SVGs but is there also a property to apply to regular text elements only?
This is what I am trying to achieve:
<div style="width: 500px; height: 500px">
Fire only when this text is clicked!
<p><!--Don't fire in this space--></p>
Fire here too!
</div>
I do not want to create a child in the parent div to capture the event.
Thanks in advance!
Is there any way to use CSS pointer-events to apply only to the text e.g. in a div? This seems to work with SVGs but is there also a property to apply to regular text elements only?
This is what I am trying to achieve:
<div style="width: 500px; height: 500px">
Fire only when this text is clicked!
<p><!--Don't fire in this space--></p>
Fire here too!
</div>
I do not want to create a child in the parent div to capture the event.
Thanks in advance!
Share Improve this question edited Mar 10, 2017 at 14:47 Ood asked Mar 10, 2017 at 14:37 OodOod 1,8354 gold badges27 silver badges50 bronze badges4 Answers
Reset to default 4Put it in a <span>
and apply your css to it
.mousePointer{
cursor: pointer;
}
<div style="width: 500px; height: 500px">
<span style="cursor: pointer;">
Fire only when this text is clicked!
</span>
<p><!--Don't fire in this space--></p>
<span style="cursor: pointer;">
Fire Here
</span>
</div>
Or
<div style="width: 500px; height: 500px">
<span class="mousePointer">
Fire only when this text is clicked!
</span>
<p><!--Don't fire in this space--></p>
<span class="mousePointer">
Fire Here
</span>
</div>
Could something like this work?
div {
pointer-events: auto;
}
div p {
pointer-events: none;
}
Or select all children like
div * {
pointer-events: none;
}
I'm not sure on your situation, but a little more html like a span tag would help keep things a little cleaner.
First, there is no text node selector in CSS. So if you don't want to add any children in your parent div, you would have to exclude all other children. For example:
<div>
No pointer events here
<div class="other-class1"></div>
<div class="other-class2"></div>
<p></p>
No pointer events here
<div>
Your selector would be something like:
div{
pointer-events: auto;
}
div:not(.other-class1):not(.other-class2):not(p){
pointer-events: none;
}
Is there any way to use CSS pointer-events to apply only to the text e.g. in a div? This seems to work with SVGs but is there also a property to apply to regular text elements only?
This is what I am trying to achieve:
<div style="width: 500px; height: 500px">
Fire only when this text is clicked!
<p><!--Don't fire in this space--></p>
Fire here too!
</div>
I do not want to create a child in the parent div to capture the event.
Thanks in advance!
Is there any way to use CSS pointer-events to apply only to the text e.g. in a div? This seems to work with SVGs but is there also a property to apply to regular text elements only?
This is what I am trying to achieve:
<div style="width: 500px; height: 500px">
Fire only when this text is clicked!
<p><!--Don't fire in this space--></p>
Fire here too!
</div>
I do not want to create a child in the parent div to capture the event.
Thanks in advance!
Share Improve this question edited Mar 10, 2017 at 14:47 Ood asked Mar 10, 2017 at 14:37 OodOod 1,8354 gold badges27 silver badges50 bronze badges4 Answers
Reset to default 4Put it in a <span>
and apply your css to it
.mousePointer{
cursor: pointer;
}
<div style="width: 500px; height: 500px">
<span style="cursor: pointer;">
Fire only when this text is clicked!
</span>
<p><!--Don't fire in this space--></p>
<span style="cursor: pointer;">
Fire Here
</span>
</div>
Or
<div style="width: 500px; height: 500px">
<span class="mousePointer">
Fire only when this text is clicked!
</span>
<p><!--Don't fire in this space--></p>
<span class="mousePointer">
Fire Here
</span>
</div>
Could something like this work?
div {
pointer-events: auto;
}
div p {
pointer-events: none;
}
Or select all children like
div * {
pointer-events: none;
}
I'm not sure on your situation, but a little more html like a span tag would help keep things a little cleaner.
First, there is no text node selector in CSS. So if you don't want to add any children in your parent div, you would have to exclude all other children. For example:
<div>
No pointer events here
<div class="other-class1"></div>
<div class="other-class2"></div>
<p></p>
No pointer events here
<div>
Your selector would be something like:
div{
pointer-events: auto;
}
div:not(.other-class1):not(.other-class2):not(p){
pointer-events: none;
}
本文标签: javascriptCSS Apply pointerevents To Text OnlyStack Overflow
版权声明:本文标题:javascript - CSS: Apply pointer-events To Text Only - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745616675a2159333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论