How to change the color of html hyperlink

王林
Release: 2023-05-29 16:01:07
Original
7163 people have browsed it

Hyperlinks in HTML are written like this:

<a href="链接URL">链接文本</a>
Copy after login

Hyperlinks can be styled through CSS. Among them, the color of the hyperlink can be set using the CSS color attribute.

The hyperlink style in the style sheet can change the color of all hyperlinks globally:

a {
  color: #0000FF; /* 设置超链接颜色为蓝色 */
}
Copy after login

Or you can change the color of only a specific hyperlink:

a.link-class {
  color: #FF0000; /* 设置类为link-class的超链接颜色为红色 */
}
Copy after login

If you want to change For the style of hyperlinks, you can use the following CSS rules:

a:link {
  color: #0000FF; /* 设置超链接未访问时的颜色为蓝色 */
  text-decoration: none; /* 去掉下划线 */
}

a:hover {
  color: #FF0000; /* 设置鼠标悬停时的颜色为红色 */
  text-decoration: underline; /* 增加下划线 */
}
Copy after login

Among the above rules, the :link pseudo-class represents unvisited links, and the :hover pseudo-class represents the mouse Link on hover. You can achieve more free and diverse effects by setting link colors and styles in different states.

The last thing to note is that when setting the hyperlink color in HTML, you need to place the style code within the <head> tag <style> tag or a separate CSS file, rather than directly within the <a> tag of the hyperlink.

The above is the detailed content of How to change the color of html hyperlink. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!