I want to ask if there is a way in CSS to style an element on a link hover. What I mean is that for example on a link hover change the body background color to blue.
I tried to search but I didn't find anything.
I want to ask if there is a way in CSS to style an element on a link hover. What I mean is that for example on a link hover change the body background color to blue.
I tried to search but I didn't find anything.
Yes it is possible to use "hover".
For example :
a: hover {
background-color:blue;
text-decoration: none;
}
However, I think it's best to share your code so that you can help you.
You can do so if the link elements preceeds or is the parent of the element whose background you want to change
UPDATE
If your html structure looks like this
<a class="my_link" href="example.html">My link</a>
<div class="my_element"></div>
In the above code, the a
tag with class my_link
proceeds the element which we want to change its background. In this type of scenario, you can use the CSS code below. Notice the ~
symbol...
Then in CSS
.my_link:hover ~ .my_element{
background: red;
}
If your html structure looks like what i have below, where the a
tag is the parent of the element whose background we want to change.
<a class="my_link" href="example.html">My link
<div class="my_element"></div>
</a>
The CSS code below would do the trick. Notice the ~
symbol is omitted
.my_link:hover .my_element{
background: red;
}