Clearing floats dynamically with CSS

后端 未结 1 1120
旧巷少年郎
旧巷少年郎 2021-01-28 04:50

I\'m trying to create a 3-column blog layout in CSS. For each new post, there will be a new div added dynamically inside of a container div.

However, I\'m running into t

相关标签:
1条回答
  • 2021-01-28 05:20

    You can use the css selector nth-child to apply clear to each third element.

    CSS

    .box:nth-child(3n + 1) {
        clear: both;
    }
    

    Demo

    How nth-child works

    Note: nth-child is not supported by IE8 and less.

    0 讨论(0)
提交回复
热议问题