Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to style links before line break element

Is there a way to style only the links that appear before the line break element?

I would like to style Link 1 and Link 2 only.

<ul>
    <li>
        <a href="#">Link 1</a> and <a href="#">Link 2</a>
        <br>
        word word word word word word <a href="#">Link 3</a>
    </li>
</ul>

I know I can easily inline the style but I was wondering if there is another way to go about doing this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes you can use a sibling combinator

a {
    background-color: pink;
}

br + a {
    background-color: transparent;
    color: red;
}
    <ul>
        <li>
            <a href="#">Link 1</a> and <a href="#">Link 2</a>
            <br>
            word word word word word word <a href="#">Link 3</a>
        </li>
    </ul>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading