Rollover button without javascript (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


spinningjennie -> Rollover button without javascript (3/9/2007 7:53:38)

I would like to show a hover effect on my button without using javascript to swap images. Is it possible?

Here's the page with the Book Here button.

Thanks for any thoughts on this.
spinningjennie




womble -> RE: Rollover button without javascript (3/9/2007 8:57:50)

Yep, you need two images and to shift the "hovered" image on hover using the CSS. There was an example I had lying around here somewhere, but as usual I can't find it. Here's an example of it used as a menu. If you view the source of that page (the CSS for each menu shown is in the page) you'll see the background position is changed for the hover state, e.g.:

#menu2 li a {
	height: 32px;
  	voice-family: "\"}\""; 
  	voice-family: inherit;
  	height: 24px;
	text-decoration: none;
	}
	
#menu2 li a:link, #menu2 li a:visited {
	color: #fff;
	display: block;
	background: url(images/menu2.gif);
	padding: 8px 0 0 10px;
	}
	
#menu2 li a:hover {
	color: #283A50;
	background: url(images/menu2.gif) 0 -32px;
	padding: 8px 0 0 10px;
	}


I used a similar idea on a site to replace a standard submit button on a form with a CSS rollover by just putting the images together as they've done on those menus. <edit>It's probably better explained here) On the hover state the background image shifts down to show the highlighted state. No idea where I put the code of the form I used, but I did manage to dig out the image, so you can see how they fix together. The top one was the normal state, the middle one the hover state, and the bottom one the pressed state. Unfortunately the 'pressed' state doesn't work cross browser without some javascript IIRC, and I've not been able to figure out/find a pure CSS method to get reliable 3 state cross browser functioning for a submit button, but it'll work for the hover state at least. There's plenty of CSS/javascript mixes out there though.



[image]local://upfiles/14943/1ECC3DA644234269860346AB691C8E6E.gif[/image]




spinningjennie -> RE: Rollover button without javascript (3/12/2007 7:52:25)

Thanks so much Womble for your detailed answer, which worked beautifully for the link and the hover!

Kind regards,
spinningjennie




jaybee -> RE: Rollover button without javascript (3/12/2007 9:08:18)

CSS rocks! [:D]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625