Solved

Adding underline to a link on hover after pressing it

Posted on 2006-10-30
2
920 Views
Last Modified: 2008-02-01
Hello,

I've added a class to some of the links in my site - "articleText" as follows:

A:hover.articleText
{
      color: #000000;
      TEXT-DECORATION: underline;
}

A:link.articleText
{
      COLOR: #000000;
      TEXT-DECORATION: none;
}

A:visited.articleText
{
      COLOR: #000000;
      TEXT-DECORATION: none;
}

A:active.articleText
{
      COLOR: #000000;
      TEXT-DECORATION: none;
}

What i want to do is add an underline to a link only on hover.
The problem is that before pressing the hyperlink, It behaves as expected but after pressing the link i am redirected to another page. When i get back to the original page, I don't see an underline on hover anymore. I guess that "visited" takes over.
How can i keep showing the underline on hover, after pressing the link?

Thanks,
Dana
0
Comment
Question by:Relegence
2 Comments
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 300 total points
ID: 17832491
All your selectors have the same specificity, so order matters.
Since :visited is declared after :hover, :visited will override :hover.
It's better to use this:

/* common definitions */
a.articleText {
     color: #000000;
     text-decoration: none;
}

/* hover definitions */
a.articleText:hover {
     text-decoration: underline;
}

This way, your 2 selectors have different specificity and you can place them in whatever order you want.
Also, it avoids a lot of redundancy which makes the code shorter and easier to maintain.

Finally, you probably don't want to set a class on each link.  Instead, you can set a class on some container and use longer selectors for your css:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<style type="text/css">

body {
  background: #eee;
  color: #000;
}

p.articleText {
     color: #888;
}

p.articleText a {
     color: #000000;
     text-decoration: none;
}

p.articleText a:hover {
     color: #000000;
     text-decoration: underline;
}

</style>
</head>
<body>
      
<p class="articleText">
Lorem <a href="http://www.google.com/">ipsum</a> dolor <a href="http://www.google.com/">sit amet</a>, consectetuer adipiscing elit.
</p>

</body>
</html>
0
 

Author Comment

by:Relegence
ID: 17833213
Thanks a lot!!!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now