When I hover over a div or class with an id of “a”, can I get the background color of a div or class with the id of “b” to change?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you can do that, but only if
#bis after#ain the HTML.If
#bcomes immediately after#a: http://jsfiddle.net/u7tYE/That’s using the adjacent sibling combinator (
+).If there are other elements between
#aand#b, you can use this: http://jsfiddle.net/u7tYE/1/That’s using the general sibling combinator (
~).Both
+and~work in all modern browsers and IE7+If
#bis a descendant of#a, you can simply use#a:hover #b.ALTERNATIVE: You can use pure CSS to do this by positioning the second element before the first. The first div is first in markup, but positioned to the right or below the second. It will work as if it were a previous sibling.