Karthick N
Karthick N

Reputation: 31

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; }

Upvotes: 2

Views: 81

Answers (2)

Noor Fahad
Noor Fahad

Reputation: 119

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

Upvotes: 0

Ashok K
Ashok K

Reputation: 191

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;
}

https://codepen.io/ashok-kannan-dev/pen/mdpWLvG

Upvotes: 2

Related Questions