0

How can I get multiple divs to transition/animate on one hover trigger?

See the update here: http://jsfiddle.net/hecyn/9/ >> CSS-Line:23 All I'm trying to here, is to get .inner and .wrap2 to rotate on one .wrap:hover. Its not working, when I add the "+" selector. How can I right this better.

Primary Question: So simply how can I write this below:

#container:hover + #cube1 + #cube2 + #cube3 { background-color: yellow; }

Second question: Above would be ok, but ultimately Im kinda trying to achieve this via CSS:

#:hoverOverSomething then{
   Do this thing;
   Do this other thing;
   Do this next thing;
}

Bear with me, little new to CSS animations... and the net is clouded and without specific simple information. Cheers.

4
  • You can try keyframe animation. Please take a look to see whether this is something you need: jsfiddle.net/maLt4dda . Documentation: developer.mozilla.org/en-US/docs/Web/CSS/@keyframes Commented Oct 3, 2015 at 9:01
  • Animating/transitioning multiple elements while hovering on another can be done but it depends on where the elements to be animated are with respect to the element that has the hover. They need to be siblings or children. You would get better answers if you post your exact markup, indicate which elements need to be animated etc than the generic do this, do that. Commented Oct 3, 2015 at 9:20
  • @Harry See the update here: jsfiddle.net/hecyn/9 >> CSS-Line:23 All im trying to here, is to get .inner and .wrap2 to rotate on one .wrap:hover. Its not working, when I add the "+" selector. How can I right this better. Commented Oct 3, 2015 at 9:32
  • 1
    Is this what you need: jsfiddle.net/ow86d5vg ? Commented Oct 3, 2015 at 9:33

2 Answers 2

1

I think you could try keyframes animation: https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes

Something like this:

.wrap:hover {
    animation: test-animation 2s linear;
}

@keyframes test-animation {
  //You can add as many ranges as you like from 0% to 100%
  0%   { opacity: 0; }
  50%   { transform: scale(1.5); }
  100% { opacity: 1; }
}

https://jsfiddle.net/maLt4dda/

Regarding the question:

How can I get multiple divs to transition/animate on one hover trigger?

Your idea is fine, but there is one mistake in the code. It should be .wrap:hover .inner,.wrap:hover + .wrap2 instead of .wrap:hover .inner + .wrap2

http://jsfiddle.net/ow86d5vg/

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

Comments

0

something like this ?

div{width:100px;height:50px;background-color:red;border:1px solid black;margin:2px;}
#container:hover ~.hover  { background-color: yellow; }
<div id="container"class="hover">Container</div>
<div id="cube1" class="hover">Cube 1</div>
<div id="cube2" class="hover">Cube 2</div>
<div id="cube3" class="hover">Cube 3</div>

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.