4

I was wondering how I could set up css pseudo classes, specifically hover so when I hover over an element, like a div with an id, the properties of a different div with an id get changed?

so normally it would be this:

#3dstack:hover {
  listed properties
}

I'm not sure what the change would be to have it hover on div with the id 3dstack and have it change another div.

3 Answers 3

6

I do not think that is possible unless the element you want to change the properties of is a descendent or a sibling of the hovered element, in which case you can do:

#myElement:hover #myElementDescendent {
    background-color: blue;
}

/*or*/

#myElement:hover + #myElementSibling {
    background-color: blue;
}

Of course you can always use jquery to do this:

$("#anelement").hover(
    function() {
        $("otherelement").css("background-color", "blue");
    });

See the differences here

Sign up to request clarification or add additional context in comments.

3 Comments

A child, a descendant, a sibling, or even a child/descendant of a sibling, or... you get the picture.
so the demo you made works, I'm trying to get this fiddle to work where you roll over and the opacity changes for in this case, a specific layer in the second containing div. jsfiddle.net/7EH7X When I roll over it nothing seems to change, I'm not sure where I'm going wrong here, the div I'm trying to change is a child and I as far as I can tell it's the same set up as what you did. In the end for this I'd like to have all four of the children change on roll over.
It is probably a problem with your inline styles which cannot be overriden by pseudo-classes.
1

This is not possible with CSS alone. You'll have to use a JavaScript event handler. For example, with jQuery's hover:

​$('#3dstack').hover(function() {
    $('#otherID').toggleClass('properties');    
});​​​​​​​

1 Comment

so I tried what you did here jsfiddle.net/7EH7X/1 and I wasn't able to get it to work, can you look at it quickly?
0

Visually you can do this using LESS, but under the hood it's actually using JavaScript.

Comments

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.