Home > Blockchain >  How can I select particular href tag using attributes
How can I select particular href tag using attributes

Time:04-04

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

CodePudding user response:

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

CodePudding user response:

you can also use class it's help you to reuse a code.

html

   <a href="https://google.com/" >Google</a>
   <a href="https://codepen.io/pen/">Codepen</a>
   <a href="https://gmail.com" >Gmail</a>

css

.selected {
  background-color: #f00;
  color: #fff;
  padding: 10px;
}

here is sample work https://codepen.io/imnoorfahad/pen/yLppaLa

  • Related