Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-18
8
Medium Priority
?
3,029 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
  • 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 600 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
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!

 
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 400 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

Independent Software Vendors: 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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

877 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