...

View Full Version : Rollover Background Color using CSS



malhyp
11-29-2008, 02:30 AM
Hi there, I have a table with a cell in it and a link.



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

rangana
11-29-2008, 03:52 AM
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.

drhowarddrfine
11-29-2008, 04:45 AM
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}

rangana
11-29-2008, 04:53 AM
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:


<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 :rolleyes:

drhowarddrfine
11-29-2008, 05:06 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum