Search code examples
cssurlhyperlinkhrefexternal

CSS: Style and color external links


I want to style all external links in my website (Xenforo). I'm trying with:

a[href ^= "http"]:after {
     content: " " url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVklEQVR4Xn3PgQkAMQhDUXfqTu7kTtkpd5RA8AInfArtQ2iRXFWT2QedAfttj2FsPIOE1eCOlEuoWWjgzYaB/IkeGOrxXhqB+uA9Bfcm0lAZuh+YIeAD+cAqSz4kCMUAAAAASUVORK5CYII=);    
}

Looks good, but i need to add red color too. How can i do that?


Solution

  • You can use the same attribute select, and style the a element with red color:

    a[href ^= "http"] {
      color: red;
    }
    
    a[href ^= "http"]::after {
         content: " " url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVklEQVR4Xn3PgQkAMQhDUXfqTu7kTtkpd5RA8AInfArtQ2iRXFWT2QedAfttj2FsPIOE1eCOlEuoWWjgzYaB/IkeGOrxXhqB+uA9Bfcm0lAZuh+YIeAD+cAqSz4kCMUAAAAASUVORK5CYII=);    
    }
    <a href="/cats">Internal</a>
    
    <a href="https://www.stackoverflow.com">Internal</a>