How to select a text node with CSS(如何使用 CSS 选择文本节点)
问题描述
我有以下 HTML 标记:
I have the following HTML markup:
<h1>
<div class="sponsor">
<span>Hello</span>
</div>
World
</h1>
当我使用 CSS 选择器 h1
时,我得到 Hello World
.
When I use the CSS selector h1
I get Hello World
.
很遗憾,我无法更改标记,我只能使用 CSS 选择器,因为我使用的是聚合 RSS 提要的系统.
I can't unfortunately change the markup and I have to use only CSS selectors because I work with the system that aggregates RSS feeds.
是否有任何 CSS 选择器我只能使用文本节点?特别是这个例子中的World
?
Is there any CSS selector which I can take only the text node? Specifically the World
in this example?
推荐答案
目前CSS的状态不能这样,查看这个链接:W3C
The current state of CSS can't do this, check this link: W3C
这里的问题是您写入屏幕的内容没有显示在 DOM 中:P.
The problem here is that the content you write to the screen doesn't show up in the DOM :P.
另外 ::outside
似乎还没有工作(至少对我来说,在 Safari 6.0.3 中)或者它根本没有产生所需的结果.
Also ::outside
doesn't seem to work yet (at least for me in Safari 6.0.3) or it simply doesn't generate the desired result yet.
检查我的小提琴,然后检查 DOM 源:JSfiddle
Check my fiddle and then check the DOM source: JSfiddle
最后还有属性选择器a { content: attr(href);}
,让CSS能够读取DOM-node属性.似乎还没有与此等效的 innerHTML
.如果这是可能的,那就太好了,而您可能能够操纵标签的内部标记.
Finally there are attribute selectors a { content: attr(href);}
, making CSS able to read DOM-node attributes. There doesn't seem to be a innerHTML
equivalent of this yet. It would be great tho if that was possible, whereas you might be able to manipulate the inner markup of a tag.
这篇关于如何使用 CSS 选择文本节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 CSS 选择文本节点


基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01