Skip to content Skip to sidebar Skip to footer

Last-child Not Working Css/html

I'm trying to have a row of four divs. As you can see im trying to get that last div a 0px margin using last-child. But i can’t seem to get rid of the margin.

Solution 1:

You have to move selector to .frontpage.

.frontpage:last-child {
  margin-right: 0;
}

Solution 2:

adding the missing closing div to each solved the problem

.frontpage {
  width: 240px;
  margin-bottom: 20px;
  margin-right: 50px;
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.frontpage img {
  margin: 10px auto;
}
.frontpage a:last-child img {
  margin-right: 0;
}
<div class="frontpage">RETRO
  <br>
  <a href="retro/index.html">
    <img src="images/name1.jpg" alt="">
  </a>
  <p>TEXT</p>
  <div class="readmore"><a href="retro/index.html">READ MORE</a>
  </div>
</div>

<div class="frontpage">RETRO
  <br>
  <a href="retro/index.html">
    <img src="images/name1.jpg" alt="">
  </a>
  <p>TEXT</p>
  <div class="readmore"><a href="retro/index.html">READ MORE</a>
  </div>
</div>

<div class="frontpage">RETRO
  <br>
  <a href="retro/index.html">
    <img src="images/name1.jpg" alt="">
  </a>
  <p>TEXT</p>
  <div class="readmore"><a href="retro/index.html">READ MORE</a>
  </div>
</div>

<div class="frontpage">RETRO
  <br>
  <a href="retro/index.html">
    <img src="images/name1.jpg" alt="">
  </a>
  <p>TEXT</p>
  <div class="readmore"><a href="retro/index.html">READ MORE</a>
  </div>
</div>

Post a Comment for "Last-child Not Working Css/html"