Jump to content

Moving divs that aren't nested


bradleybebad
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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;}

See

http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors

https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_selectors

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...