Solved

Adding a 'hover' CSS color effect for text within label tags...

Posted on 2004-04-18
8
3,003 Views
Last Modified: 2008-02-01
Hello,

I am looking for a 'hover' CSS color effect for text within label tags similar to what one would see for an <a href> link when hovering over the link text.  I'd like the color of the text to change to red when the mouse moves over the text within the label tags.

For example, here is the code that I need to function as suggested above:

<b><label style="cursor:hand;" onClick="document.forms['sites'].elements['buttons'][27].click()">SD</label></b><br>
<input type="radio" name="buttons" value="29" onClick="dataBase(this.form)">

I am hopeful that this can be done with CSS.

Thanks,

Kevin
0
Comment
Question by:lkkl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:madwax
ID: 10853894
I managed to do this with the normal css construction XXX:hover and it works in Opera but for some strange reason it doesn't work with IE, but I haven't been friend with my IE the last couples of days. But you can try it, maybe it works on your computer.

code:

<html>
<head>
</head>

<style>
#myLabel{
      color: red;
}

#myLabel:hover{
      color: blue;
}
</style>

<body>
<b><label id="myLabel" style="cursor:hand;" onClick="document.forms['sites'].elements['buttons'][27].click()">SD</label></b><br>
<input type="radio" name="buttons" value="29" onClick="dataBase(this.form)">

</body>
</html>

working example: http://www.madwax.nu/test.php

Good luck,
//jan
0
 

Author Comment

by:lkkl
ID: 10853975
Jan,

Thanks for the reply.

Yes, your red color works fine in Internet Explorer, but I cannot get the hover effect color to change to blue.

I would rather not have to resort to <a href> links and further JavaScript, as I am already doing that behind the scenes with the onClick code.

Any other thoughts?

Kevin
0
 
LVL 7

Assisted Solution

by:madwax
madwax earned 150 total points
ID: 10854043
Well, I thought it was only my IE that was strange today because as I said it worked with Opera.
You can do it with JavaScript (i.e. DHTML) and it isn't to much code. Just look at the onMouseOver and onMouseOut event-handlers below. That works in my IE.

<b><label style="cursor:hand;" onMouseOver="this.style.color='blue'" onMouseOut="this.style.color='red'" onClick="document.forms['sites'].elements['buttons'][27].click()">SD</label></b><br>
<input type="radio" name="buttons" value="29" onClick="dataBase(this.form)">

Good luck,
//jan
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10854105
IE does not support hover on any element except <a>

So you have three options:

1.  Use mouseover on the label
2.  Put a link inside the label like this: <label><a href="#">SD</a></label>
3.  Change your design.

Cd&


0
 
LVL 7

Expert Comment

by:madwax
ID: 10854122
Well, than I learned something new today as well.

But COBOLdinosaur:
So the list on: http://css.maxdesign.com.au/listamatic2/vertical03.htm wouldn't work with the hovers if it didn't use tha a:s?

0
 

Author Comment

by:lkkl
ID: 10854287
madwax,

Your solution is working perfectly, thanks!

One other question, rather than assign the onMouseOver and the onMouseOut a specific color:  "this.style.color='red'", could I assign it to a CSS name, i.e. citycolor, so that I could continue to use all CSS?

Thanks,

Kevin
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 100 total points
ID: 10854455
madwax,

Yeah for IE the a has to be in there some where:

a.class:hover a#id:hover .class a:hover #id a:hover etc all work cross-browser, but IE keeps falling further and further behind in CSS support.

 lkkl,

you could just swap the className:

.citycolor {atributes...
.countrycolor {attributes...

Then onmouseover="this.className='citycolor'"

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10859205
Glad we could help.  Thanks for the A. :^)

Cd&
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question