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
Solved

Adding underline to a link on hover after pressing it

Posted on 2006-10-30
2
923 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
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…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

791 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