[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Adding underline to a link on hover after pressing it

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

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

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

650 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