[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding underline to a link on hover after pressing it

Posted on 2006-10-30
2
Medium Priority
?
929 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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