0

I have a Vuetify v-simple-table where I need to render row css differently depending on whether a task is complete or not.

I can conditionally render the background color with the following code.

<tr :class="[done? 'greenBG' : 'whiteBG']">

The css is straight forward.

  .greenBG {
    background-color: #79ecc5;
  }
  .whiteBG {
    background-color: white;
  }

However, I cannot seem to disable the defualt :hover css. I tried connecting it to the class with this css.

  tr.greenBG:hover { background-color: green } 

If anyone can help me achieve this I'd be grateful.

1
  • Check your use of tr.greenBG:hover { background-color: green } sometimes browsers like to have that semi-colon tr.greenBG:hover { background-color: green; } OR just add to the specificity of the selector .v-data-table__wrapper tr.greenBG:hover { background-color: green; } Commented Nov 7, 2022 at 22:17

1 Answer 1

1

Try with the !important property to ensure you override any conflicting vuetify CSS

tr.greenBG:hover { 
  background-color: green !important
} 

if you really want to avoid using !important you need to be as specific as vuetify's CSS selector:

.v-data-table__wrapper
  table
  tbody
  tr.greenBG:hover:not(.v-data-table__expanded__content):not(.v-data-table__empty-wrapper) {
  background: green;
}
Sign up to request clarification or add additional context in comments.

4 Comments

Be sure to double-check that it's mandatory tho (using your browser's devtools), the usage of !important may be overkill.
Thanks. Worked a charm. I'd forgotten about !important.
Most times when you add !important to CSS that means something else is wrong (unless you are writing a reusable library) like too much CSS or the cascade is misunderstood etc.
Vuetify CSS itself sometimes uses !important so sometimes it's a necessary evil. I looked deeper and in this instance it can be avoided so the answer has been modified to include an alternative.

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.