Home >Web Front-end >Front-end Q&A >How to set the background of the link being visited with css
In css, you can use the ":active" selector and background attribute to set the background of the link you are visiting. You only need to add "a:active{background:color value/url('picture url'" to the link );}" style can set the background color or background image of the link when it is being accessed.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
cssSet the background of the link being visited
When the mouse clicks on the link, set its background color to yellow.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> a:active { background: yellow; /* background:url(img/1.jpg); */ } </style> </head> <html> <body> <a href="#">链接</a> </body> </html>
Rendering:
Description:
:active selector can set the style when you click the link.
When you click a link it becomes the active link, and :active adds special styling to active links.
Tips: :link selector sets the link style of unvisited pages, :visited selector sets the style of visited page links, :hover selector is used when the mouse is hovering over it link style.
Note: In order to produce the desired effect, in the CSS definition, :active must be located after :hover! !
Recommended tutorial: "CSS Video Tutorial"
The above is the detailed content of How to set the background of the link being visited with css. For more information, please follow other related articles on the PHP Chinese website!