是否有 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/