bradleybebad Posted March 16, 2014 Share Posted March 16, 2014 Hello, I am wondering about a simple div mover activated upon hover. Html will look like this in a nutshell:<div class="moveMe">car</div><div class="hoverMe">Hover Me</div> When these are nested, I know you can do something like:.hoverMe:hover .moveMe { position:absolute; left:-40px; /* Moves .moveMe div 40px */} This is great and all, but I cannot have nested divs for my instance. Is there a way to do this with css3/html5 or is script the solution? Quote Link to comment Share on other sites More sharing options...
george Posted March 17, 2014 Share Posted March 17, 2014 Use the so called adjacent sibling selectors from css 2. You have to change the order of your elements in the dom.<div class="hoverMe">Hover Me</div><div class="moveMe">car</div>.hoverMe:hover + .moveMe{ background-color:red;}Seehttp://www.w3.org/TR/CSS2/selector.html#adjacent-selectorshttps://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_selectors Quote Link to comment Share on other sites More sharing options...
bradleybebad Posted March 17, 2014 Author Share Posted March 17, 2014 Hah! Simple as that! Thanks George, I thought there might be a good css solution. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.