简体   繁体   English

是否可以针对<p></p>只用 CSS?

[英]Is it possible to target <p>&nbsp;</p> with just CSS?

I know I can remove p tags only with &nbsp;我知道我只能用&nbsp;删除 p 标签being in them with JS/jQuery like so:像这样使用 JS/jQuery 在其中:

$("p").filter(function(){
    return $.trim(this.innerHTML) === "&nbsp;"
}).remove();

But is it possible to target these with just CSS.但是是否可以仅使用 CSS 来定位这些。 Something like these doesn't work:像这样的东西不起作用:

p[&nbsp;] { display: none; }
p:contains('&nbsp;') { display: none; }

Unfortunately this isn't possible with just CSS.不幸的是,这仅靠 CSS 是不可能的。 :contains used to be part of the CSS3 spec but has now been removed. :contains曾经是 CSS3 规范的一部分,但现在已被删除。

I have the same problem, and I solved with CSS pseudo selector: 'has:'我有同样的问题,我用 CSS 伪选择器解决了:'has:'

  p:has('&nbsp;') {
  display: none;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM