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 specify all links with a certain pattern with CSS

#p1 a,#p2 a,#p3 a,#p4 a,#p5 a, etc.

I have thousands of them.

How can I specify all of them with CSS

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

tried #p*
tried id^="p"

>Solution :

Works for me.

[id^="p"] a {
  color: red;
}

[id^="z"] a {
  color: green;
  text-decoration: none;
}

[id^="z"] a:hover {
  color: blue;
  text-decoration: underline;
}
<p id="p1"><a href="">P One</a></p>
<p id="p2"><a href="">P Two</a></p>
<p id="p3"><a href="">P Three</a></p>
<p id="p4"><a href="">P Four</a></p>

<p id="z1"><a href="">Z One</a></p>
<p id="z2"><a href="">Z Two</a></p>
<p id="z3"><a href="">Z Three</a></p>
<p id="z4"><a href="">Z Four</a></p>

But I’m sure you could find a better selector than "id starts with p". Giving all the relevant links a class would seem a more robust solution.

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