Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

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!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

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.

Posted by: Ed Donaldson at November 29, 2005 7:57 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

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









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, 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.









Uniblue: Free Virus Scan

Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 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.

[whiteboard marker tray]