Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Rollover Background Color using CSS

    Hi there, I have a table with a cell in it and a link.

    Code:
    <table width="100" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>
    <div align="center">
    <a href="#">Link</a>
    </div>
    </td>
    </tr>
    </table>
    Can anyone let me know how I would make the background change color using a CSS?

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Which background? The cell? the div? or the link?

    CSS can only affect the later.

    If you want to change a parent element when hovering over a child element, then your best bet would be JS.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Senior Coder
    Join Date
    Oct 2005
    Posts
    1,340
    Thanks
    0
    Thanked 61 Times in 60 Posts
    Quote Originally Posted by rangana View Post
    Which background? The cell? the div? or the link?

    CSS can only affect the later.

    If you want to change a parent element when hovering over a child element, then your best bet would be JS.
    None of that is true.

    To change the color of the td:
    td:hover{background-color:#ddd}
    td div:hover{background-color:#ddd}
    td a:hover{background-color:#ddd}

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    That doesn't makes sense.

    How does it affect it's parent element, I might be at mistake, but this is what I came up with your stylesheet:
    Code:
    <style>
    td:hover{background-color:#ddd}
    td div:hover{background-color:#ddd}
    td a:hover{background-color:#ddd} 
    </style>
    <table width="100" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>
    <div align="center">
    <a href="#">Link</a>
    </div>
    </td>
    </tr>
    </table>
    Show me how you would change the TD element when you hover over the a element
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    Senior Coder
    Join Date
    Oct 2005
    Posts
    1,340
    Thanks
    0
    Thanked 61 Times in 60 Posts
    Yeah, I misread that line. There may be a submission for parent selection to the CSS3 committee but not now. However you can adjust the link to the height/width of the td and accomplish the same thing.


  •  

    Posting Permissions

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