Specify the external link style with CSS

Source: Internet
Author: User

Most information websites, such as Wikipedia, will specify a specific style for external links (TAGS). As a user, it is a good experience to know that the link is a resource pointing to another site at a glance. Many websites perform external link check on the server side, add a property value of 'rel = external ', or add a class of 'external' to the external link. Sometimes this is impossible or difficult to use. After hanging out on the Internet, I found the following CSS style code useful for external links:

A [href ^ = "http: //"]: not ([href * = "mysite.com"]), a [href ^ = "https: //"]: not ([href * = "mysite.com"]), a [href ^ = "//"]: not ([href * = "mysite.com"]), {/* external link style. You can also use the: before or: after pseudo class if needed! */}
Note that you may need to add a browser-specific prefix for CSS rules in some browsers.
You must first limit the start character of the link protocol and then limit the domain name. So that the internal link does not match, and the external link matches the regular expression.

We recommend that you add this code snippet to your library in case you need it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.