Results 1 to 2 of 2

Thread: Change Color Upon Hover

  1. #1
    Join Date
    Nov 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Change Color Upon Hover

    Is there an easy way to set certain text on a page to be one color, and another color when you hover over it? Right now, I'm just using a link code where I make false links out of the text I want to change colors, and they change to the color I want when hovering over them. It works exactly the same, but I don't want links going nowhere on my page.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Unfortunately, in IE there isn't. Since it is the most widely used browser, even though other modern browsers support the pseudo-class :hover on most elements, this strategy is virtually useless as, IE only supports it with links.

    You can use javascript to disable the links and use something innocuous for the link so that even if it is clicked in a non-javascript enabled browser, nothing bad will happen. Something like so will work well in most browsers:

    HTML Code:
    <a href="javascript:void();" onclick="return false">Text Here</a>
    You can give the tag(s) a class and only apply your hover effect to that class so that real links can use their own set or default hover behavior:

    HTML Code:
    <a class="hEffect" href="javascript:void();" onclick="return false">Text Here</a>
    Then in your stylesheet:

    Code:
    .hEffect {
    cursor:text;
    color:black;
    text-decoration:none;
    }
    
    .hEffect:hover {
    color:red;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •