search
HomeWeb Front-endCSS TutorialCSS Tutorial (3) Pseudo Class - Dynamic Link

CSS Tutorial (3) Pseudo Class - Dynamic Link

Apr 01, 2017 pm 02:00 PM
cssPseudo classdynamicTutorialLink

Pseudo class can be regarded as a special class selector, which is a special selector that can be automatically recognized by browsers that support CSS. Its greatest use is that it can define different style effects for links in different states.

1. Syntax

The syntax of pseudo-class is to add a pseudo-class (pseudo-class) to the original syntax:
selector:pseudo-class {property: value}
(Selector: Pseudo-class {Attribute: Value})
Pseudo-class is different from the class. It has been defined by CSS. You cannot use other names at will like the class selector. According to the above syntax, it can be interpreted as an object ( selector) in a special state (pseudo-class).

Class selectors and other selectors can also be mixed with pseudo-classes:
selector.class:pseudo-class {property: value}
(selector.class:pseudo-class{property: Value})

2. Pseudo-classes of anchors

The most commonly used pseudo-classes of the four a (anchor) elements are the four pseudo-classes of the a (anchor) element, which represent the four different states of the dynamic link: link, visited, active, hover (unvisited links, visited links, active links and mouseover links). We define different effects for them respectively:
a:link {color: #FF0000; text-decoration: none} /* Unvisited link*/
a:visited {color: #00FF00; text-decoration : none} /* Visited link*/
a:hover {color: #FF00FF; text-decoration: underline} /* Mouse over link*/
a:active {color: #0000FF; text -decoration: underline} /* Activate link*/
(In the above example, the color of the link is red and underlined when it is not accessed, it is green and underlined when it is accessed, and it is blue and underlined when the link is activated. , it is purple and underlined when the mouse is on the link)
Note: Sometimes it has an effect when the mouse points to the link before the link is accessed, but it has no effect when the mouse points to the link again after the link is accessed. This is because you put a:hover in front of a:visited. In this case, because the latter one has a higher priority, the effect of a:hover will be ignored when the link is accessed. Therefore, according to the stacking order, when we define these link styles, we must write them in the order of a:link, a:visited, a:hover, and a:actived.

3. Pseudo-class and class selectors

By combining pseudo-classes and classes, you can create several sets of different link effects on the same page. For example, we define a One group link is red and blue after visiting; the other group is green and yellow after visiting:
a.red:link {color: #FF0000}
a.red:visited {color: #0000FF}
a.blue:link {color: #00FF00}
a.blue:visited {color: #FF00FF}
Now applied on a different link:
This is the first set of links
This is the second set of links> ;

4. Other pseudo-classes

In addition, CSS2 also defines pseudo-classes for the first word and first line (first-letter and first-line), which can be used to modify the first letter or first line of an element. Set different styles.
Look at this example below. We define the size of the first letter of text in the paragraph mark to be 3 times the default size:

......


This is a paragraph, and the first word of this paragraph is enlarged.



Let’s define another example of the first line style:

......



This is the first line of the paragraph
This is the second line of the paragraph
This is the third line of the paragraph



(In the above example, the first line of the paragraph is red, and the second and third lines are the default colors)

Note: The pseudo-classes of the first word and first line need to be supported by IE5.5 or above.

The above is the detailed content of CSS Tutorial (3) Pseudo Class - Dynamic Link. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
The Lost CSS Tricks of Cohost.orgThe Lost CSS Tricks of Cohost.orgApr 25, 2025 am 09:51 AM

In this post, Blackle Mori shows you a few of the hacks found while trying to push the limits of Cohost’s HTML support. Use these if you dare, lest you too get labelled a CSS criminal.

Next Level CSS Styling for CursorsNext Level CSS Styling for CursorsApr 23, 2025 am 11:04 AM

Custom cursors with CSS are great, but we can take things to the next level with JavaScript. Using JavaScript, we can transition between cursor states, place dynamic text within the cursor, apply complex animations, and apply filters.

Worlds Collide: Keyframe Collision Detection Using Style QueriesWorlds Collide: Keyframe Collision Detection Using Style QueriesApr 23, 2025 am 10:42 AM

Interactive CSS animations with elements ricocheting off each other seem more plausible in 2025. While it’s unnecessary to implement Pong in CSS, the increasing flexibility and power of CSS reinforce Lee's suspicion that one day it will be a

Using CSS backdrop-filter for UI EffectsUsing CSS backdrop-filter for UI EffectsApr 23, 2025 am 10:20 AM

Tips and tricks on utilizing the CSS backdrop-filter property to style user interfaces. You’ll learn how to layer backdrop filters among multiple elements, and integrate them with other CSS graphical effects to create elaborate designs.

SMIL on?SMIL on?Apr 23, 2025 am 09:57 AM

Well, it turns out that SVG's built-in animation features were never deprecated as planned. Sure, CSS and JavaScript are more than capable of carrying the load, but it's good to know that SMIL is not dead in the water as previously

'Pretty' is in the eye of the beholder'Pretty' is in the eye of the beholderApr 23, 2025 am 09:40 AM

Yay, let's jump for text-wrap: pretty landing in Safari Technology Preview! But beware that it's different from how it works in Chromium browsers.

CSS-Tricks Chronicles XLIIICSS-Tricks Chronicles XLIIIApr 23, 2025 am 09:35 AM

This CSS-Tricks update highlights significant progress in the Almanac, recent podcast appearances, a new CSS counters guide, and the addition of several new authors contributing valuable content.

Tailwind's @apply Feature is Better Than it SoundsTailwind's @apply Feature is Better Than it SoundsApr 23, 2025 am 09:23 AM

Most of the time, people showcase Tailwind's @apply feature with one of Tailwind's single-property utilities (which changes a single CSS declaration). When showcased this way, @apply doesn't sound promising at all. So obvio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools