'How can I select particular href tag using attributes
I want to create the selector using a tag href attributes. I try the below one but not working well. Please check the below code
HTML
<a href="https://google.com/">Google</a> <a href="https://codepen.io/pen/">Codepen</a>
CSS
ahref="https://google.com/" { background-color: #f00; color: #fff; padding: 10px; }
Solution 1:[1]
You can use it like this. Also Here I attached the codepen. Plesae try this
a[href="https://google.com/"] {
background-color: #f00;
color: #fff;
padding: 10px;
}
Solution 2:[2]
you can also use class it's help you to reuse a code.
html
<a href="https://google.com/" class="selected">Google</a>
<a href="https://codepen.io/pen/">Codepen</a>
<a href="https://gmail.com" class="selected">Gmail</a>
css
.selected {
background-color: #f00;
color: #fff;
padding: 10px;
}
here is sample work https://codepen.io/imnoorfahad/pen/yLppaLa
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ashok K |
| Solution 2 | Noor Fahad |
