473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Image underline during hover

NevadaSam
I want to use a dotted underline when I hover over a text link, but I don't want this to show up when I hover over a image link. Is there a way I can do this without calling a different class when I have an image link?


Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2.  
  3. img {
  4.     background-color:#FFFFFF;
  5.     border: 1px solid #ff12fc;
  6.     padding: 5px;
  7.     margin: 5px 5px 0 0;
  8. }
  9.  
  10. a:hover {
  11.     color:#666;
  12.     text-decoration: none;
  13.     border-bottom:dotted;
  14. }
  15.  
  16. a:hover img {
  17.     background-color:#00FF00;
  18.     border: 1px solid #ff12fc;
  19.     padding: 5px;
  20.     margin: 5px 5px 0 0;
  21.     text-decoration: none; /* the underline shouldn't show, but it does */
  22. }
  23.  
  24. </style>
  25.  
Thanks for looking at this.

Sam
May 7 '07 #1
1 16130
pbmods
5,821 Expert 4TB
I want to use a dotted underline when I hover over a text link, but I don't want this to show up when I hover over a image link. Is there a way I can do this without calling a different class when I have an image link?
Unfortunately not, because the A element is what has the dotted border, not the image.

[EDIT: And now I completely refute what I just said :P]
Now, you can specify the child of the A element instead using:

Expand|Select|Wrap|Line Numbers
  1.         a:first-child:hover {
  2.             border-bottom: 5px dashed #666;
  3.         }
  4.  
  5.         a:hover > img {
  6.             background-color:#00FF00;
  7.             border: 1px solid #ff12fc;
  8.         }
  9.  
But this doesn't work in IE. Which is another rant for the next few years.

Now, this works in Safari, but I don't know if it'll work in IE:

Expand|Select|Wrap|Line Numbers
  1.         a:hover {
  2.             color:#666;
  3.             text-decoration: none;
  4.         }
  5.  
  6.         a > *:hover {
  7.             border-bottom: 5px dashed #999999;
  8.         }
  9.  
  10.         a:hover > img {
  11.             background-color:#00FF00;
  12.             border: 1px solid #ff12fc;
  13.         }
  14.  
[Incidentally, '>' means 'child', so the rule will only be triggered for an element that is a child node [as opposed to a descendent] of the A element.]

For more info on CSS selectors, check out this document:
http://css.maxdesign.com.au/selectutorial/index.htm
May 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal bar below the image. This allows :hover effects...
9
by: David Ross | last post by:
In some cases, I indicate links with both a small image and also text, both in the same anchor. When I upgrade my pages to incluce DOCTYPE for HTML 4.01 transitional, the underline for the link...
2
by: mike | last post by:
Hello, What I would like is to float some text around the image where the text starts align on the left or right of the image aligned to the top of the image and then wrap around the image. I have...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
29
by: jmaxsherkimer | last post by:
the site we're working on has some anchor links, you click them they scroll to the bottom of the page with the answers to the questions linked on to. is there anyway to make it so that the links...
6
by: fredo | last post by:
A few days ago, Jim answered (THANK YOU, Jim) my question about how to make an image pop up when an image link is hovered. That discussion is here: ...
7
by: Cate Archer | last post by:
I want to have a border around an image that changes color when the mouse hovers over it. The following code works perfectly in FireFox but not in Internet Exploiter. The text link changes color...
5
by: studentofknowledge | last post by:
hi guys im new to javascript and need some guidence please.. im trying to display a 400x400 pixel coloured area in the middle of a webpage that stays in the middle with a browser window resize....
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.