Old 17-04-2006, 09:15   #1 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Rollover image css code

Until now I've used terribly messy dreamweaver code for rollover images.

Does anyone know the code for a simple mouse over rollover image in css/html ?
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 17-04-2006, 09:28   #2 (permalink)
Scott
sanddancer
 
Scott's Avatar
 
Join Date: Feb 2004
Location: South Shields
Posts: 2,990
Send a message via MSN to Scott
__________________
  Reply With Quote
Old 17-04-2006, 11:50   #3 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
  Reply With Quote
Old 17-04-2006, 12:03   #4 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Ok thanks lads - i'll give it a shot.
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 17-04-2006, 12:15   #5 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Not having much success. Hopefully one of you will be able to identify the problem.

I've created a 1.jpg and a 2.jpg (1 being its normal state, and 2 when the mouse rolls over). It isn't working, however, I experimented with text, and on the mouse over it works... but I'm obviously doing something wrong.


Here is my code -

(thanks)

Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <style type="text/css"> #menu a { background: url("1.jpg") top left no-repeat; } #menu a:hover { background-image: url("2.jpg"); } } </style> <body> <div id="menu"> <a href=""><img src="1.jpg" width="287" height="150"></a> <a href="">test with text</a> </div> </body> </html>
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 17-04-2006, 14:14   #6 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Anyone around? Could do with sorting this out this evening.
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 17-04-2006, 15:05   #7 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
You're displaying that image 3 times, once in the img tag, once in the first a, once in the second a.

Try:

Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <style type="text/css"> #menu a { background: url("1.jpg") top left no-repeat; display: block; height: (height-of-image)px; width: (width-of-image)px; } #menu a:hover { background-image: url("2.jpg"); } } <--- Remove that, where'd it come from?. </style> <body> <div id="menu"> <a href="#">test with text</a> </div> </body> </html>
You should really be using the link I showed. 2 states in one image will eliminate the flicker on rollover.
  Reply With Quote
Old 18-04-2006, 09:06   #8 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
oK thats great. Got the code working..

However, I want it to be just an "image rollover".. not image rollover on text. How do I get rid of the text but still allow the images to rollover?
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 18-04-2006, 09:27   #9 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Is this the right way? or a bodge?

<div id="menu">
<a href="#">&nbsp;</a>

Then applying text-decoration none in the css ?

Surely its a bodge...
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 18-04-2006, 10:20   #10 (permalink)
captainK
Registered User
 
captainK's Avatar
 
Join Date: Dec 2005
Location: Leeds
Posts: 56
Stick your text within span tags and add this style:

#menu span{
display:block;
width:0;
height:0;
overflow:hidden;
}
  Reply With Quote
Old 18-04-2006, 11:49   #11 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Use image replacement like captainK suggests. You'll have to give each <a> an id or class to feed it its own background image.
  Reply With Quote
Old 18-04-2006, 14:42   #12 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Quote:
Originally Posted by captainK
Stick your text within span tags and add this style:

#menu span{
display:block;
width:0;
height:0;
overflow:hidden;
}

I don't want any text, I just want mouse roll overs on an image... so its normal state as 1.jpg and then rollover 2.jpg

Any idea?
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 18-04-2006, 17:23   #13 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Bit of a bump. Sorry to be a pain.
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 19-04-2006, 00:48   #14 (permalink)
seen.to
unusual suspect ™
 
seen.to's Avatar
 
Join Date: Jul 2004
Location: DE, USA
Posts: 3,067
Quote:
Originally Posted by Accurate
I don't want any text, I just want mouse roll overs on an image... so its normal state as 1.jpg and then rollover 2.jpg

Any idea?

But you still want to put text in there then hide it for accessibility/SEO purposes.
__________________
  Reply With Quote
Old 19-04-2006, 05:29   #15 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
Oh right. Let me see then if that works then!
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 20-04-2006, 09:35   #16 (permalink)
Accurate
Accurate
 
Accurate's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 1,311
This works, is my code ok though?

Code:
<html> <head> <title>Mouse Over test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <style type="text/css"> #menu a { background: url("1.jpg") top left no-repeat; display: block; height: 205 px; width: 205 px; text-decoration: none; } #menu a:hover { background-image: url("2.gif"); text-decoration: none; } </style> <body> <div id="menu"> <a href="#">&nbsp;</a> </div> </body> </html>
__________________
decent web hosting - www.balue.com
.
  Reply With Quote
Old 20-04-2006, 10:48   #17 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Yeah, but if you use image replacement, you'll have a text alternative.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8