内联样式属性的 CSS 选择器同时排除属性值

标签 css css-selectors

是否有 CSS 选择器可以根据元素的内联样式属性值从元素中排除“display: none”?所以我需要编写一个 css 选择器,其中不存在“显示:无”。

<div style = "position: absolute; top: 12px; left: 84px; display: none;">

寻找如下内容:

div[not:style * = 'display: none'] 

div:not[style*='display: none'] 

最佳答案

你很接近;你只是缺少 not 的括号选择器:

div:not([style*='display: none']) {}

注意:这是区分空格和大小写的。换句话说,它将匹配:

<div style="display: none"></div>

还有这个:

<div style="display:None"></div>

您可以通过在 ] 之前添加 s 使其不区分大小写,并通过添加另一个过滤器使其不区分空格:

div:not([style*='display: none' s]):not([style*='display:none' s]) {}

关于内联样式属性的 CSS 选择器同时排除属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57380776/

相关文章:

asp.net - 像 WinForm 应用程序一样在网页中锚定控件

html - 如何使用 :nth-child? 将背景应用于无序列表

html - 如何选择除特定类及其后代之外的所有元素?

JQuery 选项卡 - 更改输入条目选项卡的背景颜色

javascript - 文本不在第二行拆分

html - 如何更改CSS属性

css - 如何使:focus,:active与:hover相同

html - CSS 内联覆盖 li 不工作

javascript - 如何将 png 背景图像和填充颜色添加到 SVG?

html - 下拉菜单 HTML/CSS