Finalmix6
Finalmix6

Reputation: 415

CSS : target an "<a>" tag element

Say you have this html syntax :

<a href="#myId" aria-controls="hotel" role="tab" data-toggle="tab" aria-expanded="true">My Hotel</a>

What would be the CSS to target this tag, if I want to select the "aria-expanded" value, and the "href" value ?

Upvotes: 1

Views: 516

Answers (2)

Amirreza Noori
Amirreza Noori

Reputation: 1525

You can use this selector

a[href="#myId"][aria-expanded="true"]

more info: https://www.w3.org/TR/CSS2/selector.html#attribute-selectors

Upvotes: 2

Kameron
Kameron

Reputation: 10846

The CSS to target the a href and aria-expanded value would consist of the following:

a[aria-expanded="true"] {
  background-color: lightgrey;
}
<a href="#myId" aria-controls="hotel" role="tab" data-toggle="tab" aria-expanded="true">My Hotel</a>

Upvotes: 1

Related Questions