6

I am trying to create some margin between 2 divs when the both of them have a common parent, so the code as it follows:

   <div class="parent">
      <div class="child">hello</div>
      <div class="child">hello</div>
   </div>

and css

 .child{background:#ccc; padding:20px}
 .parent .child + .parent .child{ margin-top:520px; }

you can see in this link: http://jsfiddle.net/hjcY7/

And also in the link there is another example that it works but when the div dont have a parent.

Any ideas?

Thanks!

1 Answer 1

7

You have to set the rule this way:

.parent .child + .child {
   margin-top: 520px;
}

You can see it in action here http://jsfiddle.net/hjcY7/1/.

Take a look at the Adjacent sibling selectors on W3.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.