4

I have the following CSS:

 td: hover {
 background-color:red;
 }
 td {
 cursor: pointer;
 background-color: rgb(150,150,150);
 }

and my HTML is just:

<table>
<tr><td> </td></tr>
</table>

I can't get the hover to work. Why is that?

asked Apr 19, 2013 at 15:06

3 Answers 3

12

:hover is a pseudo-selector, and everything beginning with : is such (e.g. :active, :before etc.).

This can be confused with specifying values:

something: value;

So you need to think about pseudo-selectors as separate objects, not a value.

That's why you need to fix your td: hover so it looks like td:hover.

Note that if you put a space after td like so:

td :hover { ...

This is equal to:

td: *:hover { ...

and therefore will select all items descending from td and apply a style on hover to them (see this example).

Remember, spaces have a meaning in CSS.

answered Apr 19, 2013 at 15:29
Sign up to request clarification or add additional context in comments.

Comments

6

You need to remove the space before :hover:

td:hover {
 background-color: red;
}
MMM
7,3402 gold badges27 silver badges42 bronze badges
answered Apr 19, 2013 at 15:06

Comments

2

You just need to remove the space between td :hover as the <td> has no descendants ..

td:hover will work

http://jsfiddle.net/xwYTa/

answered Apr 19, 2013 at 15:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.