How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

寻∝梦
Release: 2018-09-04 13:40:16
Original
105790 people have browsed it

Everyone should be familiar with the

hyperlinka tag. This article mainly talks about the basic css style settings of the a tag. It introduces four color changes. I hope you can practice more. Below Let us read this article together

First we need to know the color setting of the html a tag:

We all know that in html the a tag is in the web page What does the default color look like? Now try the code to see:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP中文网</title>
</head>
<body>
<a href="#">php中文网</a>
</body>
</html>
Copy after login

This is the code for a basic html document. Look at the display effect in the browser:

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

The unclicked URL above is blue like this, and after being clicked, it is purple. Such a link does not look good. We need to set a color for the a tag. For example, if I want to set a color for unclicked URLs, let's say red. Before being clicked, it is red, and after being clicked, it is black. Let’s do the effect:

<head>
<meta charset="utf-8">
<title>PHP中文网</title>
<style type="text/css">
a:link{color:red;}
a:visited{color:black;}
</style>
</head>
<body>
<a href="#">php中文网</a>
</body>
Copy after login

This is a simple css code, let’s take a look at the effect:

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is The style that has not been accessed is red;

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is the style that has been accessed and is black. Let’s explain the code:

  • a:link: It is an unvisited style. You can add many things to it, such as removing underlines, changing colors and other functions. ;

  • a:visited: It is the style after being clicked. You can also add many elements to it, and you can underline, change color, zoom in and other functions;

  • a:hover: This is the mouse hover style. There will be examples of this later. Let’s get to know it first. You can set the color to change when the mouse is parked at the position of the hyperlink;

  • a:active: This is said to be an activated style. To put it simply, it is a style that will appear instantly when you click the mouse. This style is found on many websites;

Now let’s take a look at an example, the effect of putting all the above four in:

<head>
<meta charset="utf-8">
<title>PHP中文网</title>
<style type="text/css">
a:link{color:red;}
a:visited{color:black;}
a:hover{color:pink;}
a:active{color:#ccc;}
</style>
</head>
<body>
<a href="#">php中文网</a>
</body>
Copy after login

Let’s take a look now at the browser The effect shown in:

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is the effect of mouse hovering, made

How to set the color of html a tag? Summary of color settings for hyperlinks (css style)

This is the click moment Effect. (Want to see more, please click css video tutorial)

Summary of hyperlink a tag:

So there are four types of a tag Now that we have introduced the CSS styles of anchor pseudo-classes, let’s recall the four uses. One is the unclicked style, which is the style that is displayed normally without being clicked. The style after being clicked is the style after you click the tag. , and another one is the mouse hover style, which changes when you put the mouse on it. This effect is very useful. You will know its use later. The last one is the effect at the moment of click. These four This effect can be said to be the four necessary styles for a tags, so the settings can be better.

【Editor’s Recommendation】

html5 What is the usage of datalist tag? Here are usage examples of the datalist tag

#What is the include tag in html? html include implements configuration parsing

The above is the detailed content of How to set the color of html a tag? Summary of color settings for hyperlinks (css style). 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