0
<a class="u-textlink" href=“www.link.com" rel="category tag">Sustainability</a>

Is there a way to target only rel attribute with the name “Sustainability”? But only with CSS.

I tried a[rel="category tag”] but then all the rels get CSS and I want to target just the rel with word Sustainability if I target a[href="www.link.com”] then all the links get targeted.

j08691
  • 204,283
  • 31
  • 260
  • 272
  • Note the curly quotes in your example. Make sure that your actual code isn't using them. – j08691 Feb 09 '23 at 21:34
  • Using CSS, there isn't a way to reference the text in an anchor. If you can modify your anchor to include a data attribute, then you can use pure CSS to access it. – imvain2 Feb 09 '23 at 21:52

1 Answers1

0

It's not possible to do with CSS. You can either use a workaround in CSS or JS to do it.

I think of all the available options these are the most common: data attributes (especially for utility/component styling), IDs if unique, or just adding an additional class in this case.

There are lots of options. Here are a few examples:

/* green for all */

a[rel="category tag"] {
  color: green;
}


/* override only for the ones with the data-attribute */

a[rel="category tag"][data-only-me] {
  color: darkblue;
}


/* override only for the ones with the extra rel */

a[rel="category tag special"] {
  color: red;
}


/* override only for a specific class */

a.special {
  color: hotpink;
}


/* override only for the id */

#special-snowflake {
  color: orange;
}
<a class="u-textlink" href=“www.link.com" data-only-me="" rel="category tag">Sustainability</a>
<a class="u-textlink" href=“www.link.com" rel="category tag">Something else</a>
<a class="u-textlink" href=“www.link.com" rel="category tag special">Something else</a>
<a class="u-textlink special" href=“www.link.com" rel="category tag special">Something else</a>
<a id="special-snowflake" class="u-textlink" href=“www.link.com " rel="category tag ">Something else</a>
F. Müller
  • 3,969
  • 8
  • 38
  • 49