CSS选择器:如何选择非元素同级节点? [英] CSS selector: how to select non-element sibling node?

查看:299
本文介绍了CSS选择器:如何选择非元素同级节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此处的规范: http://www.w3. org/TR/CSS21/selector.html#adjacent-selectors

相邻的同级选择器具有以下语法:E1 + E2,其中 E2是选择器的主题.选择器是否匹配E1和E2 在文档树中共享同一父级,并且E1紧接在其前 E2,忽略非元素节点(例如文本节点和注释).

Adjacent sibling selectors have the following syntax: E1 + E2, where E2 is the subject of the selector. The selector matches if E1 and E2 share the same parent in the document tree and E1 immediately precedes E2, ignoring non-element nodes (such as text nodes and comments).

那么我们如何选择非元素同级节点.例如:在下面的html中,我们如何选择非元素文本"文本?

So how can we select the non-element sibling node. For example: in the following html, how can we select the "Non-element text" text?

<div><label>Some text here</label> Non-element text</div>

推荐答案

您不能. CSS选择器只能选择元素节点.这就是为什么相邻的同级组合器按说明工作的原因.

You can't. CSS selectors can only select element nodes. This is why the adjacent sibling combinator works as described.

如果需要应用样式,请尝试将其应用于div,并在label中覆盖它们.当然,这确实取决于您要应用的样式,因为某些样式无法撤消或受到继承.

If you need to apply styles, try applying them to the div and overriding them in the label. This does depend on what styles you're applying, of course, since some of the styles can't be undone or are subject to inheritance.

这篇关于CSS选择器:如何选择非元素同级节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆