How to set hyperlink style with css

王林
Release: 2021-06-21 09:16:16
Original
5951 people have browsed it

The way to set the hyperlink style in css is to add a pseudo-class to the hyperlink, such as [a:visited {color:#00FF00;}]. [a:visited] indicates links that the user has visited.

How to set hyperlink style with css

The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.

If we want to set the style of a hyperlink, we can actually use any css attribute, such as color, font, background, etc. But if you want to set a special style, you need to use pseudo classes. Let's take a look at pseudo-classes together.

Tip: Special links can have different styles, depending on their status.

The four link statuses are:

  • a:link - normal, unvisited link

  • a: visited - the link that the user has visited

  • a:hover - when the user mouses over the link

  • a:active - the link is The moment you click

Code example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
<style>
a:link {color:#000000;}      /* 未访问链接*/
a:visited {color:#00FF00;}  /* 已访问链接 */
a:hover {color:#FF00FF;}  /* 鼠标移动到链接上 */
a:active {color:#0000FF;}  /* 鼠标点击时 */
</style>
</head>
<body>
<p><b><a href="/css/" target="_blank">这是一个链接</a></b></p>
<p><b>注意:</b> a:hover 必须在 a:link 和 a:visited 之后,需要严格按顺序才能看到效果。</p>
<p><b>注意:</b> a:active 必须在 a:hover 之后。</p>
</body>
</html>
Copy after login

Let’s take a look at the running effect:

How to set hyperlink style with css

Related recommendations: css video tutorial

The above is the detailed content of How to set hyperlink style with css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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