CSS '+' selector not working

I am trying to create some margin between two divs when both of them have a common parent code, so the following code:

<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 at this link: http://jsfiddle.net/hjcY7/

And also in the link there is another example that it works, but when the div has no parent.

Any ideas?

Thanks!

+6
source share
1 answer

You must set the rule as follows:

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

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

See Related Selectors on W3.

+7
source

Source: https://habr.com/ru/post/957109/


All Articles