CSS Selector for No-Children-But-Not-Empty(无子但非空的 CSS 选择器)
问题描述
我想在下面的 HTML 片段中选择 BONKERS.它的区别在于它在 <code> 块中是单独的,而它的所有兄弟都包含 <a> 的.:empty 是显而易见的选择,但由于文本节点而无法使用.我以为我知道这些东西,但这让我发疯了.
I want to select BONKERS in the HTML fragment below. Its distinction is that it's alone in a <code> block whereas all its siblings contain <a>'s. :empty is the obvious choice, but won't work due to the text node. I thought I knew this stuff but this is driving me, well, bonkers.
<ul class="Reference">
<li class="level4">
<code class="active-voice">
<a href="some/url/x" version="2">
mauve
</a>
</code>
<li class="level8">
<code class="active-voice">
BONKERS
</code>
</li>
<li class="level9 subclass">
<code class="active-voice">
<a href="some/url/c" version="2">
cerise
</a>
</code>
</li>
</ul>
我需要一个纯 CSS 解决方案(JS 不是一个选项),并且无法控制源 HTML.
I need a pure CSS solution (JS isn't an option), and have no control over the source HTML.
呸!
推荐答案
你可以按照这个方法.通过您想要的任何 CSS 设置 code 元素的样式,然后重置那些在 anchor 的样式中可继承的 CSS 样式,即:
You can follow this approach. Style the code elements by whatever CSS you want and then reset those CSS styles which are inheritable in anchor's styles i.e.:
演示:http://jsfiddle.net/GCu2D/1062/
CSS:
code {
color: green;
font-weight: bold;
}
code a{
color: red;/*Reset any inheritable css*/
font-weight: normal; /*Reset any inheritable css*/
}
您可能不需要重置所有样式,因为并非所有样式都由 anchor 从 code 元素继承
You might not need to reset all styles because not all styles are inherited by anchor from the code element
这是您真正可以考虑的一种解决方案.
This is one solution which you can really consider.
这篇关于无子但非空的 CSS 选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无子但非空的 CSS 选择器
基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
