Children of a selector: one with margin left another with right

1

Next, I've always had this question I have this html structure

<!-- wrap1 -->
<div class="wrap">
  <div class="filho">
    (...)
  </div>
</div>

<!-- wrap2 -->
<div class="wrap">
  <div class="filho">
    (...)
  </div>
</div>

I know I can do this in other ways, but I'd like to know how I can select the .wrap .root (from the first) and get it to get the left margin and the .wrap .root (from the second) get margin right? The scenario is exactly that. Thanks to anyone who can clarify.

    
asked by anonymous 02.02.2018 / 16:53

1 answer

0

It is possible using the pseudo-class :nth-child :

.wrap:nth-child(1) .filho{
   margin-left: 50px;
}

.wrap:nth-child(2) .filho{
   margin-right: 50px;
}
<!-- wrap1 -->
<div class="wrap">
  <div class="filho">
    (...)
  </div>
</div>

<!-- wrap2 -->
<div class="wrap">
  <div class="filho">
    (...)
  </div>
</div>
    
02.02.2018 / 17:05