Home Ask Login Register

Developers Planet

Your answer is one click away!

Programer January 2017

How to change both div background color and inside content color on mouse hover?

I want CSS tricks to change background color and text color inside the div on mouse hover. i.e. when I hover anywhere inside the div the text color should change dynamically(without even hovering on text).


VKK January 2017

The CSS code below would change the background color and text color of all divs on hover. If you only want this applied to a specific div change div:hover to div#id-of-div:hover.

div:hover {

Zack Kirby January 2017

For modern browsers, you can use the following:

div:hover {
    background-color: red;
    color: white;

If you are looking to support older browsers, you'll need to use some javascript or jQuery to add a hover class to the div, then style the hover class.

Post Status

Asked in January 2017
Viewed 1,295 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life