简体   繁体   中英

Can I apply CSS pseudo classes to just one link rather then all of them?

<a href = "www.fashjdkjdasfh.com">fashjdkjdasfh.com</a>
<a href = "www.hjdshf.com">hjdshf</a>

How would I go about making one of those links a different color then the other in my CSS document?

I would recommend number 12 from here (The 30 CSS selectors you must memorize)

Basically you can search the href object for a string.

HTML

<a href = "www.google.com">Google</a>
<a href = "www.yahoo.com">Yahoo</a>

CSS

a {
    color:green;
}

a [href*="google"] {
    color:red;
}

The above link is a GREAT article about CSS selectors and goes into depth with examples of many different selectors including the pseudo selectors.

I suggest you should use Id attribute in tag. By doing you can add extended CSS properties for that specific hyperlink.

<style>
  .a { ... }
  .a#myid { color:red; ... }

</style>

Just give it a class and assign the CSS accordingly:

<a href="http://www.fashjdkjdasfh.com">fashjdkjdasfh.com</a>
<a href="http://www.hjdshf.com" class="redlink">hjdshf</a>

<style>
  .redlink { color: red; }
</style>

BTW, I'd use http in your href or alternatively // .

http://www.stackoverflow.com or //www.stackoverflow.com

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM