Advertisement

06.07.2006 at 12:06AM PDT, ID: 21877391
[x]
Attachment Details

rollover image to change text color and viceversa

Asked by soniya in Cascading Style Sheets (CSS)

Tags: change, text, rollover, color, image

Hello,

For my top navigation, I have a row of text links link1 link2 link 3 and so on
On the next row i have a picture associated  with each of the links...img 1 img2 img 3 and so on
 I want to following actions:
1) On rollover on an image link i want it to add a border to the image to highlight the image
2) On rollover on an image link i want textlink to be  highlighted to red color.
3) On rollover on a text link i want it to add a border to the image to highlight the image
4) On rollover on a text link i want textlink to be  highlighted to red color.

In short I want the image to be highlighted with red border and the text link to change color to red whenevr mouse is hovered over eithe text link or the image link.

I can not make it work properly when all 4 actions are taking place. at a time only three of them are taking place.

I am using
1.swap image function for changing the image to show red border around the image.
2. change property function to change the color of  text link when hover mouse over the image map
Here is the code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}
</script>

<style type="text/css">
<!--
a {      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 13px;
      color: #ffffff;
      text-decoration: none;      
}
a:hover {
      color: #ff0000;
      text-decoration: none;      
}
-->
</style>
</head>

<body onload="MM_preloadImages('images/header_01_red.gif','images/header_02_red.gif')">
<table width="79px" border="0" cellspacing="0" cellpadding="0" align=center>
  <tr>
    <td bgcolor="#000000"  align=center>
     <a href="#" onmouseover="document.myimage1.src='images/header_01_red.gif';" onmouseout="document.myimage1.src='images/header_01.gif';"> <div id="link1" >eat</div></a>
</td>
   
  </tr>
  <tr>
    <td> <img src="images/header_01.gif" name="myimage1" width=79 height=117 border="0" usemap="#myimage1Map" ></td>
      
  </tr>
</table>
<map name="myimage1Map" id="myimage1Map">
<area shape="circle" coords="42,57,37" href="#" onmouseover="MM_swapImage('myimage1','','images/header_01_red.gif',1);MM_changeProp('link1','','style.color','#ff0000','DIV')" onmouseout="MM_swapImgRestore();MM_changeProp('link1','','style.color','#ffffff','DIV')" />
</map>
</body>
</html>

I have uploaded the images and this page at http://www.huestechnologies.com/demo/rollover.html

Here the textlink is not changing to red.

while in other file where i changed the code to
<td bgcolor="#000000"  align=center>
     <div id="link1" ><a href="#" onmouseover="document.myimage1.src='images/header_01_red.gif';" onmouseout="document.myimage1.src='images/header_01.gif';"> eat</a></div>
</td>
   
  </tr>
the text link is changing but hovering the mouse over the image is not changing the color of text link.
the second example is at
http://www.huestechnologies.com/demo/rollover2.html

Is there any other simpler way to achieve this functionality?
I posted this question here because I think this can be done with css with / without using javascript.
Start Free Trial
 
 
[+][-]06.07.2006 at 01:54PM PDT, ID: 16856429

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Cascading Style Sheets (CSS)
Tags: change, text, rollover, color, image
Sign Up Now!
Solution Provided By: radnor
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.07.2006 at 08:20PM PDT, ID: 16858435

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 05:58AM PDT, ID: 16860740

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 06:01AM PDT, ID: 16860770

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 07:21AM PDT, ID: 16861556

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 08:13AM PDT, ID: 16862157

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 08:54AM PDT, ID: 16862558

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 09:23AM PDT, ID: 16862835

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.08.2006 at 09:46AM PDT, ID: 16863016

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2006 at 06:03AM PDT, ID: 16983602

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32