I am trying to change the background color of a row of Divs on hover but I cannot figure out how to do that.
// row 1
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
// row 2
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
// row 3
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
How do I hover on a row and highlight that rows Divs by changing their background color?
(My Divs are inside a css grid).
Thank you for any help.
3
Answers
it’s better to put each row into another Div and add Class to them and then:
You can set the background color upon hover for all divs like this in your css file:
Now the div will become yellow upon hovering.
If you want to make it specific for each row. You can wrap a row in a another div and give it an id. Then reference the ID in your css for the specific styling.
Your HTML:
Your CSS:
You should use a hover pseudo style for the divs like
If you need to differentiate the rows, please extend your class style with a row class or something specific