?
Solved

Adding underline to a link on hover after pressing it

Posted on 2006-10-30
2
Medium Priority
?
926 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

765 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