简体   繁体   中英

How to ignore 2 break lines in HTML and CSS?

I'm debugging an existing Java/JSP/Struts application, somehow it generates 2 break lines and left a large space in the page :

<Br></Br>
<Br></Br>

So I searched around and found I can use the following in CSS to ignore break lines :

br { display: none; }

See my previous question : Where did extra space come from in html of Struts app?

But this will cause all break lines to be ignored in the app, and not the ideal solution I'm looking for, I think the br's were generated by Struts and hard to control, so I wonder if there is a way in CSS to define 2 breaks as nothing [to be ignored], maybe something like this ?

brbr { display: none; }
br.br { display: none; }

I tried it, didn't work, must be in wrong format, any CSS experts here can answer my question ?

Use + in your selector:

br + br { display: none; }

From W3 Documentation

E + F : Matches any F element immediately preceded by a sibling element E.

Simple:

br + br {display:none;}

This selects a br that directly follows another br using the + selector.

Ref: Section 5.1 Pattern matching and 5.7 Adjacent sibling selectors

br supports class why not give then a class

<br class="hey" />

CSS

.hey{
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