If 2 HTML elements are followed, select the first one with CSS

1

I have this HTML structure:

<br>
<br>
<blockquote>

I want to select with CSS the <br> element that goes just before the <blockquote> only when they go one after the other.

I'm trying with:

br + blockquote ~ br {//estilos}

But it does not work for me. If it were the other way around there would be no problem because it would serve me with a blockquote + br . I am following the rules of CSS selectors .

    
asked by JetLagFox 12.10.2018 в 08:33
source

2 answers

1

I agree with what @Ale says, but if you do it that way and have it several times, it will only take the last one. You have to use classes to differentiate them. If for example you have it 2 times, it would be something like this:

HTML:

<br class="primero">
<br class="primero">
<blockquote>


<br class="segundo">
<br class="segundo">
<blockquote>

CSS:

br.primero:last-of-type{
}

br.segundo:last-of-type{
}

Another way is to use a specific class to differentiate the last:

<br>
<br class="ultimo">
<blockquote>

<br>
<br class="ultimo">
<blockquote>

<br>
<br class="ultimo">
<blockquote>

<br>
<br class="ultimo">
<blockquote>

br.ultimo{
}
    
answered by 12.10.2018 в 15:16
0

With that structure that you are showing you could use br:last-of-type and you would be selecting the last of the br

You could also put an id to the br and ready

    
answered by 12.10.2018 в 15:09