简体   繁体   中英

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

I know I can remove p tags only with &nbsp;being in them with JS/jQuery like so:

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

But is it possible to target these with just CSS. Something like these doesn't work:

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

Unfortunately this isn't possible with just CSS. :contains used to be part of the CSS3 spec but has now been removed.

I have the same problem, and I solved with CSS pseudo selector: 'has:'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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