Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


How do I disable a CSS anchor hover?

"Dave, I've been having great results using the hover attribute within my CSS style sheets, but when I have graphical buttons, sometimes they end up with the background-color change hover attribute as a small drop-shadow that only appears when the mouse is over the element. Y'know what I mean? How do I disable this?"

Dave's Answer:

This is a classic challenge when you start working with anchor color changes within Cascading Style Sheets. It's all well and good to have a:link, a:visited, a:hover and a:active in your CSS, but typically it ends up being defined for the entire document and that's not always a desirable result.

To sidestep that, you can most easily create a class that has the hover effect and apply it to the blocks where you want your tags to have this nice effect.

It might look like this:

<style type="text/css" rel="stylesheet">
.hoverpink a:hover { background-color:#fcc }
</style>
Then you can use it within a block of HTML by simply adding a class="hoverpink" in the div tag itself: <div class="hoverpink">

Another approach would be for you to use a CSS style that lets you define the behavior of the anchor's hover for the entire document, then override it with your images, like this:

<style type="text/css" rel="stylesheet">
.nohover a:hover { background-color: transparent; }
</style>
You'd use this by wrapping your img tags with either a div or span, depending on context, like this:
<div class="nohover"><a href="/ask.html">
<img src="/Graphics/marker-tray.gif" border="0" width="749" 
alt="whiteboard markers" height="31" /></a></div>
If you view the source to this very Web page and scroll to the very bottom, you'll see this is exactly what I've done with the little marker tray graphic.

That should help you change the sometimes confusing CSS anchor attributes into what you seek!


Related HTML, JavaScript and Web Site Programming articles:
✔   How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔   Can I embed a Facebook search box on my blog site?
I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔   Can I use CSS for drop shadows on my blog?
I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔   How can I embed interactive photo panoramas on my site/blog?
I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔   How can I create a Twitter search URL shortcut?
I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  








Reader Comments To Date: 9

Ed Donaldson said, on November 29, 2005 7:57 PM:

If you choose to "disguise" a link as a non-link, you can also specify the cursor to be a nondescript arrow (default) by including '.nohover a:hover { background-color: transparent; cursor: default;}" in your style declaration. You can also disable the status bar display with javascript. I use this for a link to the database backend for my customers.

Denis Co said, on October 26, 2009 5:26 PM:

Somebody has to say it!
hey guys the hover or Mouseover for menu is a very bad habit. it makes the menu access very hard for some.

Consider onclick/active instead.
I wish there was a way to disable/replace them all or a setting.
Feel free to reply if you know a trick that would do that.

sree said, on November 18, 2009 8:08 AM:

A:link
{
COLOR: #0033cc;
TEXT-DECORATION: none;
}

A[Disabled]:hover
{
text-decoration:none;
}

A:visited
{
COLOR: #0033cc;
TEXT-DECORATION: none;
}

A:hover
{
COLOR: #0033cc;
TEXT-DECORATION: underline;
}

XU said, on March 11, 2010 6:56 AM:

Cool!

Yadaf said, on April 22, 2010 3:34 PM:

Hello Dev Taylor,
I am trying to build my site in google Blogger . I am facing problem with my header . I have added an image in my header . When I mouse over it it shows the homepage link and when I click on it, page started to reload again .

So, I want to disable the mouse over function on it . My blog address is- "http://bangladigonto.blogspot.com" . Please Visit my blog and give me a solution .

-Thanks

Seemas said, on September 26, 2010 6:53 AM:

how to disable the status bar display of a link ??

Ceres said, on October 30, 2010 10:25 PM:

OMG THANK YOU!!! I have been to at least 40 different sites in the last 3 days and all of there suggestions didn't work but yours does! :D my hair thanks you since it is no longer being pulled in frustration over that stupid sidebar.

Axinar said, on May 8, 2011 12:44 PM:

Thanks for this tutorial; it saved me alot of headaches, made me learn more about CSS and fixed my problem, which was caused after setting up RSS to point to a set of page anchors... only to find that the a refs, that were not really links, were triggering the default hover behaviour to be applied to text that was wrapped for anchoring when they were meant to stay black in my grand design.

Thanks again!

Scylla said, on January 28, 2012 11:25 AM:

YOU ARE AMAZING! I looked about 6 or 7 others websites and nothing worked but when I opened your page I fixed it in 2 minutes.

Thank you]

Website Coming soon

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

I do have a comment, now that you mention it!











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.