Link to home
Start Free TrialLog in
Avatar of no158
no158

asked on

Problem with div links and hover state background

http://csn.mc.com/test.aspx

I'm trying to implement a html/css horizontal menu where divs are the links using onclick events.

The divs have an inital background but when you hover over the div it will change the new background.

Here is some of the code from the link above to make this easier.


<%@ Page Language="C#" AutoEventWireup="true" Title="Converged Sensor Networking" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head runat="server">
    <link rel="Stylesheet" href="MASTERMaster_page.css" type="text/css" media="all" />
    <!--[if IE 6]>
    <link rel="stylesheet" type="text/css" href="ie6fix.css" />
    <![endif]-->
</head>
<body>
<div id="learn" onclick="location.href='http:/csn.mc.com/learn.aspx';" style="cursor:pointer;"></div>
<div id="differ" onclick="location.href='http://csn.mc.com/differ.aspx';" style="cursor:pointer;"></div>
<div id="solve" onclick="location.href='http://csn.mc.com/solve.aspx';" style="cursor:pointer;"></div>
<div id="contact" onclick="location.href='http://csn.mc.com/contact.aspx';" style="cursor:pointer;"></div>
</body>
<html>
 
 Here is the .css code
 
div#learn {
	background: url('img/global_nav/learn.jpg') 0 0 no-repeat;
	border:none;
	width:88px;
	height:27px;
	float:left;
	margin-top:80px;
}
div#differ {
	background: url('img/global_nav/differentiate.jpg') 0 0 no-repeat;
	border:none;
	width:173px;
	height:27px;
	float:left;
	margin-top:80px;
}
div#solve {
	background: url('img/global_nav/solve.jpg') 0 0 no-repeat;
	border:none;
	width:105px;
	height:27px;
	float:left;
	margin-top:80px;
}
div#contact {
	background: url('img/global_nav/contact.jpg') 0 0 no-repeat;
	border:none;
	width:108px;
	height:27px;
	float:left;
	margin-top:80px;
}
 
div#learn:hover {background: url('img/global_nav/learn-over.jpg') 0 0 no-repeat;}
div#differ:hover {background: url('img/global_nav/differentiate-over.jpg') 0 0 no-repeat;}
div#solve:hover {background: url('img/global_nav/solve-over.jpg') 0 0 no-repeat;}
div#contact:hover {background: url('img/global_nav/contact-over.jpg') 0 0 no-repeat;}
 
div#learn:visited {background: url('img/global_nav/learn.jpg') 0 0 no-repeat;}
div#differ:visited {background: url('img/global_nav/differentiate.jpg') 0 0 no-repeat;}
div#solve:visited {background: url('img/global_nav/solve.jpg') 0 0 no-repeat;}
div#contact:visited {background: url('img/global_nav/contact.jpg') 0 0 no-repeat;}

Open in new window

Avatar of shonk
shonk
Flag of United Kingdom of Great Britain and Northern Ireland image

That seems to be working here, at least in FF3 and IE7... What's the problem?

The only thing I would suggest is preloading the images so that there isn't a delay in them showing.
Avatar of no158
no158

ASKER

Dose not seem to be working in IE6. The img wont switch.
Avatar of no158

ASKER

How do I preload the images ?
There is no hover or horizontal menus working on IE6 at all, and no color change like Moz- FF2.  

Your CSS is lacking some basic link styling, like the following --

A:link       {color : #0000FF; text-decoration: none; background-color:#CCCCCC;}
A:visited   {color : #0000FF; text-decoration: none; background-color:#CCCCCC;}
A:active   {color : #0000FF; text-decoration: none;background-color:#CCCCCC;}
A:hover    {color: #CC0000; text-decoration: underline; background-color:#aa8844;}

Add that and adjust those values until you get what you want.

I don't see where or why you need to preload images on this page -- there are no images I can see.
Avatar of no158

ASKER

Each part of the menu is an img...

The background for the div is an image i.e. the background is the text ("Learn"), which is an img. When you hover over the img will switch from a gray looking img to a orange looking img.


How would you preload, because I can see how it would matter when you reload the page on IE7. There seems to be a little choppiness in the img.
ASKER CERTIFIED SOLUTION
Avatar of shonk
shonk
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
shonk's preloading in place and hiding is fine.  

The other way we used to do it is load them all at the bottom of the screen, like this --
<IMG SRC = "images/wbln.jpg" NAME = "img11" HEIGHT="1" WIDTH="1">
 then use javascript to swap the images into the right place when mousing over.  Either way works.
Avatar of no158

ASKER

I did the joined picture trick where you take the rollover state and the non-rollover state and join them side by side so they are only 1 picture and just moved the position.

It fixed the loading choppiness and also fixed a bug in opera but it still did not fix the problem with IE6. The image loads but it will not move the position on rollover.

Any ideas?

<head><link rel="Stylesheet" href="MASTERMaster_page.css" type="text/css" media="all" />
    <!--[if IE 6]>
    <link rel="stylesheet" type="text/css" href="ie6fix.css" />
    <![endif]-->
<title>
	Converged Sensor Networking
</title></head>
<body>
<div id="learn" onclick="location.href='http://csn.mc.com/learn.aspx';" style="cursor:pointer;"></div>
<div id="differ" onclick="location.href='http://csn.mc.com/differ.aspx';" style="cursor:pointer;"></div>
<div id="solve" onclick="location.href='http://csn.mc.com/solve.aspx';" style="cursor:pointer;"></div>
<div id="contact" onclick="location.href='http://csn.mc.com/contact.aspx';" style="cursor:pointer;"></div>
</body>
<html>
 
The new CSS:
 
div#learn {
	background: url('img/global_nav/learnC.jpg') 0 0 no-repeat;
	border:none;
	width:88px;
	height:27px;
	float:left;
	margin-top:78px;
	position:relative;
}
div#differ {
	background: url('img/global_nav/differentiateC.jpg') 0 0 no-repeat;
	border:none;
	width:173px;
	height:27px;
	float:left;
	margin-top:78px;
	position:relative;
}
div#solve {
	background: url('img/global_nav/solveC.jpg') 0 0 no-repeat;
	border:none;
	width:105px;
	height:27px;
	float:left;
	margin-top:78px;
	position:relative;
}
div#contact {
	background: url('img/global_nav/contactC.jpg') 0 0 no-repeat;
	border:none;
	width:108px;
	height:27px;
	float:left;
	margin-top:78px;
	position:relative;
}
 
div#learn:hover {background-position: -88px 0;}
div#differ:hover {background-position: -173px 0;}
div#solve:hover {background-position: -105px 0;}
div#contact:hover {background-position: -108px 0;}

Open in new window

Avatar of no158

ASKER

It seems the problem is because of this code:

div#learn:hover

is there another way to do the hover state for IE6?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of no158

ASKER

if someone does not have javaScript enabled then this feature will not work. I'm trying to avoid it but I might have a fix for it using an htc file. It will scan the .css file and if it find the :hover it will run a function to take care of this problem. I'm just wondering if the htc is working like a javaScript.

Can be found at www.xs4all.nl/peterned/csshover.html

Avatar of no158

ASKER

Ahh forget it, I give up on trying to avoid javaScript. Everyone should have it enabled....

I'm already using onclick so I might as well use onmouseover.

Thanks guys.

You have both been a big help.
So javascript was the solution then, not the one you accepted as the solution? You decided that my suggestion of on mouse over was the best solution -- just for the record?
Avatar of no158

ASKER

I'm using the javaScript and the trick with loading one picture. The mouseover will just change the position to the picture.

Thats why I split up the points evenly. I figured you were both so helpful, should spread the wealth.

For the record. I didn't know about the accepted solution and assisted solution till now. If i had to do it again I would put your answer as the accepted solution and shonk as the assisted.