Problem with last-Child

Asked

Viewed 130 times

0

a problem I believe that simple for who is known in the area, my problem is this, I have a div "father" and inside this div I have 6 li and inside the div "father" has the div "box_padrao" and this "box_padrao" displays 3 by lines there has a margin-right of 5px and to take and margin of the last li use the last-Hild, only that the problem comes here, it only takes the margin of the "box_padrao 6", and I need you to take from the "box_padrao 3" too, as I would do this magic? thank you very much for your attention

<style type="text/css">
  .pai{
    width: 408px;
  }
  .pai ul li .box_padrao{
    float: left;
    margin: 0 5px 0 0;
    width: 132px;
    height: 150px;
    background: #ccc;
  }
  .pai ul li:last-child .box_padrao{
    margin: 0;
  }
</style>
<div class="pai">
    <ul>
      <li><div class="box_padrao">1</div></li>
      <li><div class="box_padrao">2</div></li>
      <li><div class="box_padrao">3</div></li>
      <li><div class="box_padrao">4</div></li>
      <li><div class="box_padrao">5</div></li>
      <li><div class="box_padrao">6</div></li>
    </ul>
</div>

1 answer

1


The name of magic is: nth-child

.pai ul li:nth-child(3n) .box_padrao{
  [...]
}

every three li it will apply this property. which in case, in 3 and 6

  • friend and how I would take the margin-bottom of 4,5,6 without affecting the margin-bottom: of 1,2,3 ?

  • .pai ul li:nth-child(n+4) .box_padrao{&#xA; margin-bottom: none;&#xA;}

  • friend excuse my insistence, and how I would take the margin-top of 3 div without affecting the other div

  • I managed to resolve, I took a look at this article http://blog.rafaelcavalcante.com/como-o-seletor-nth-child-works/ thank you very much for your help, I help myself a lot and I could not score 1 point in your reply, hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.