0

I am using the below code to highlight a table rows, but it does not highlight the row.

It highlight only the current cell and it only turns the font color to white when i hover over the actual font.

Is there something I am missing?

HTML and CSS:

.schedule tr:not(:first-child) :hover{
        font-weight:bold;
        cursor:default;
        background-color:#B80D9F;
        color:white;
    }
    
    .schedule{
        border-spacing:0px;
    }


 
 <table class="schedule" width="90%">
        <tbody>
            <tr>
                <td style="width:50%">hello1</td>
                <td style="width:50%">123</td>
            </tr>
            <tr>
                <td style="width:50%">hello2</td>
                <td style="width:50%">123</td>
            </tr>
        </tbody>
    </table>

Update:

All the answers below are correct, but do not address the second issue with the font not changing to white when a <a> tag is used.

Why would the font-color not change?

1
  • anchors default font color is blue. so you have to specify your styles for anchor tags separately. Commented Dec 1, 2015 at 6:11

5 Answers 5

3

Remove the space before :hover, because actually your try to access to the children of tr, not the tr itself

And color is setted with custom style on a, you have to add another css selector on a to change its color :

.schedule tr:not(:first-child):hover a{
   color:white;
}
Sign up to request clarification or add additional context in comments.

2 Comments

I cannot believe it was that simple... Thank you :)
One last thing... It seems if the text contains a <a> it does not change the font color. Can you see why?
0

Change your css as following, you have mistake in your rule :-

.schedule tr:not(:first-child):hover{
    font-weight:bold;
    cursor:default;
    background-color:#B80D9F;
    color:white;
}

It may help you.

3 Comments

It would better help for OP if you explain what mistake he/she did.
I have already added first line that you have mistake in your rule :)
I understand that but still if you try to be more specific then it would be good for OP. For ex: answer given by @Arnaud , So that OP can know that exactly where and in which line/rule he did mistake. :)
0

change your css to:

.schedule tr:not(:first-child):hover{
   font-weight:bold;
   cursor:default;
   background-color:#B80D9F;
   color:white;
}

.schedule{
   border-spacing:0px;
}

the issue you had was the space before the :hover

Comments

0

the mistake is with the space

.schedule tr:not(:first-child):hover{
    font-weight:bold;
    cursor:default;
    background-color:#B80D9F;
    color:white;
}

.schedule{
    border-spacing:0px;
}

Comments

0

All things updated.Please see working Link and enjoy!! Spacing problem before :hover

HTML:

<table class="schedule" width="90%">
<tbody>
    <tr>
        <td style="width:50%">hello1</td>
        <td style="width:50%">123</td>
    </tr>
    <tr>
        <td style="width:50%"><a href="">hello2</a></td>
        <td style="width:50%"><a href="">123</a></td>
    </tr>
</tbody>

CSS:

 .schedule tr:not(:first-child):hover{
  font-weight:bold;
  cursor:default;
  background-color:#B80D9F;
  color:white;
}
 .schedule tr:not(:first-child):hover a{
  color:white;
  text-decoration:none;
 }
.schedule tr:not(:first-child) a{
 text-decoration:none;
 color:black;
 }
.schedule{
 border-spacing:0px;
}

Comments

Your Answer

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.