Learn Hyperlink A Tag

Learn Hyperlink A Tag

ask:
I have styled the hyperlink using CSS, but it doesn't work on hover. Why is this happening? Is it a browser problem?
answer:
Although you think it may be a browser problem, it is more likely that the order of your style definitions is wrong. In order to ensure that you can see the connection styles in different states, the correct style order should be:
"link-visited-hover-active" or "LVHA" (abbreviation).
Core content:
Each selector has a "specificity" and if two selectors are applied to the same element, the selector with the higher specificity will win and take precedence. For example:
P.hithere {color: green;} /* specificity = 1,1 */
P {color: red;} /* specificity = 1 */
Any paragraph content with class=hithere set will appear green instead of red. Both selectors set the color, but the selector with higher specificity wins.
How do pseudo-classes affect specificity? They have exactly the same weighting values, and the following styles have the same specificity weighting values:
A:link {color: blue;} /* specificity = 1,1 */
A:active {color: red;} /* specificity = 1,1 */
A:hover {color: magenta;} /* specificity = 1,1 */
A:visited {color: purple;} /* specificity = 1,1 */
These are the style settings for hyperlinks. In most cases, you need to set several of these styles at the same time. For example, an unvisited hyperlink can have different styles for "mouse over" and "mouse activated" when the mouse is hovered over and clicked. Since the above three rules can all be applied to hyperlinks and all selectors have the same specificity, the last style "wins" according to the rules. So the "active" style will never be shown because it is always overwritten by the "hover" style (i.e. "hover" takes precedence). Now let's analyze what happens when you hover over a visited hyperlink. The result is always purple :(, because its "visited" style always takes precedence over other state style rules (including "active" and "hover").
This is why CSS1 recommends the following order of styles:
A:link
A: visited
A:hover
A:active
In fact, the order of the first two styles can be swapped, because a hyperlink cannot exist in both the "unvisited" and "visited" states at the same time. ( :link means " unvisited "; I don't know why it's not defined that way.)
CSS2 now allows pseudo-classes to appear in "groups", for example:
A:visited:hover {color: maroon;} /* specificity = 2,1 */
A:link:hover {color: magenta;} /* specificity = 2,1 */
A:hover:active {color: cyan;} /* specificity = 2,1 */
They have the same specificity, but they apply to fundamentally different beasts, and so don't conflict. You can get hover-active combinations, for example.
How do you understand the "specificity" involved in this article? Specificity can understand strings of numbers that are not simply concatenated together. An example from the above:
P.hithere {color: green;} /* specificity = 11 */
P {color: red;} /* specificity = 1 */
This seems to be a simple operation based on decimal. However, the calculation of "specificity" cannot use the decimal algorithm. For example, if you use 15 selectors together, their "specificity" weight value is still lower than that of a simple class selector. Example:
.hello {color: red;} /* specificity = 10 */
HTML BODY DIV UL LI OL LI UL LI OL LI UL LI OL LI (color: green;} /* specificity = 15 */
"10" is actually a "1" followed by a "zero", not a "ten". We can use hexadecimal to describe the specificitiy of the previous style rule, like this:
.hello {color: red;} /* specificity = 10 */
HTML BODY DIV UL LI OL LI UL LI OL LI UL LI OL LI (color: green;} /* specificity = F */
The only problem is if you want to add two or more selectors to the second style rule, then you might end up with a specificity of "17", which would be confusing again. In fact, the specificity may be infinite, so in order to avoid more confusion, it is recommended to use commas to separate the specificity values.
Webmaster's suggestion : Practice calculating the weighted value of specificity repeatedly. The CSS settings of the website reflect your ability to control the page. In the development of dynamic websites, the status of CSS is also very important. Read more materials, practice more, and come to 123WORDPRESS.COM more often! If you like this site, please promote it! Thanks for reading

<<:  Example code for implementing card waterfall layout with css3 column

>>:  Use three.js to achieve cool acid style 3D page effects

Recommend

Example code for setting hot links and coordinate values ​​for web images

Sometimes you need to set several areas on a pict...

React hooks introductory tutorial

State Hooks Examples: import { useState } from &#...

React sample code to implement automatic browser refresh

Table of contents What is front-end routing? How ...

Docker Getting Started Installation Tutorial (Beginner Edition)

Doccer Introduction: Docker is a container-relate...

Solution to the problem of slow docker pull image speed

Currently, Docker has an official mirror for Chin...

The difference between ENTRYPOINT and CMD in Dockerfile

In the Docker system learning tutorial, we learne...

React Native environment installation process

react-native installation process 1.npx react-nat...

Detailed tutorial on building Gitlab server on CentOS8.1

There is no need to say much about the difference...

The difference between html empty link href="#" and href="javascript:void(0)"

# contains a location information. The default anc...

Detailed explanation of location and rewrite usage in nginx

1. Summary of location usage Location can locate ...

Ubuntu 20.04 sets a static IP address (including different versions)

Because Ubuntu 20.04 manages the network through ...

Pure HTML and CSS to achieve JD carousel effect

The JD carousel was implemented using pure HTML a...