1

I have this code in html

<div class="small_world_news">
  <div class="small_world_news_article_box">
    <div>
      <img class="small_picture_world_news" src="http://placehold.it/100x100">
      <h4 class="small_title_world_news"> Doors open to Japan's new 30B industry </h4>
      <ul class="author_etc">
        <li>December 14, 2016</li>
        <li>
          <div class="first">by</div>
          <div class="blue">John Doe</div>
        </li>
      </ul>
    </div>
    <div>
      <img class="small_picture_world_news" src="http://placehold.it/100x100">
      <h4 class="small_title_world_news"> Doors open to Japan's new 30B industry </h4>
      <ul class="author_etc">
        <li>December 14, 2016</li>
        <li>
          <div class="first">by</div>
          <div class="blue">John Doe</div>
        </li>
      </ul>
    </div>
    <div>
      <img class="small_picture_world_news" src="http://placehold.it/100x100">
      <h4 class="small_title_world_news"> Doors open to Japan's new 30B industry </h4>
      <ul class="author_etc">
        <li>December 14, 2016</li>
        <li>
          <div class="first">by</div>
          <div class="blue">John Doe</div>
        </li>
      </ul>
    </div>
  </div>
</div>

And I need 20px space between firstarticle-secondarticle and secondarticle-thirdarticle. Also I need 30px space after last article. I know that I can make named divs, but I want to with child of class "small_world_news_Article_box". But this code doesent work.

.small_world_news_article_box {
  margin-bottom: 20px;
}

.small_world_news_article_box:last-child {
  margin-bottom: 30px;
}
Vojta Matras
  • 69
  • 1
  • 8
  • Possible duplicate of [:last-child not working as expected?](http://stackoverflow.com/questions/18995362/last-child-not-working-as-expected) – Dave R. Mar 15 '17 at 13:38

3 Answers3

2

Target the child div of the class like so:

.small_world_news_article_box>div {
margin-bottom: 20px;
}
.small_world_news_article_box>div:last-child{
margin-bottom: 30px;
}

Codepen: http://codepen.io/dragosmicu/pen/ZeXbNY

Clearfix:

.clearfix:before,
.clearfix:after {
  content: "";
  display: table;
} 
.clearfix:after {
  clear: both;
}
Dragos Micu
  • 341
  • 1
  • 9
1

Try this:

.small_world_news_article_box > div {
  margin-bottom: 20px;
}
.small_world_news_article_box > div:last-child{
  margin-bottom: 30px;
}
Shiva127
  • 2,413
  • 1
  • 23
  • 27
0

:last-child works on the element theres a few of not the containing element.

In your case the unnamed div the article is contained in is what you need to apply the class to. So what you need is:

.small_world_news_article_box > div{
    margin-bottom: 20px;
    overflow: auto;
}
.small_world_news_article_box > div:last-child{
    margin-bottom: 30px;
}

You can read more about how it all works here: https://css-tricks.com/almanac/selectors/l/last-child/

Web Develop Wolf
  • 5,996
  • 12
  • 52
  • 101