I am trying to style my <a>
tags via CSS
but they are not changing.
HTML
<div id="menu">
<ul>
<li><a href="#">Bugs</a></li>
</ul>
</div>
CSS
a.active, a.link, a.visited {
color: black;
text-decoration: none;
}
a.hover {
color: black;
text-decoration: underline;
font-style: italic;
}
Not sure why the CSS would not work. The external stylesheet works for the other tags used throughout the page (IE: <h1>
is styled properly and they are on the same .css
file)
In addition, links can be styled differently depending on what state they are in.
The four links states are:
- a:link - a normal, unvisited link
- a:visited - a link the user has visited
- a:hover - a link when the user mouses over it
- a:active - a link the moment it is clicked
See example below:
/* unvisited link */ a:link { color: blue; } /* visited link */ a:visited { color: aquamarine; } /* mouse over link */ a:hover { color: green; } /* selected link */ a:active { color: red; }
<a href="#a">This is a link</a>
When setting the style for several link states, there are some order rules:
- a:hover MUST come after a:link
- and a:visited a:active MUST come after a:hover
它应该是,
a:active, a:link, a:visited, a:hover
If you want to style on hover, link and visited use
a:hover a:link a:visited
in your css
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.