How to show the first N elements of a block and hide the others in css?

假装没事ソ 提交于 2019-11-30 04:41:22
  1. You have a .notarow as the first child, so you have to account for that in your :nth-child() formula. Because of that .notarow, your first .row becomes the second child overall of the parent, so you have to count starting from the second to the fourth:

    .row:nth-child(-n+4){
        display:block;
    }
    

    Updated fiddle

  2. What you're doing is fine.

You don't even need CSS3 selectors:

.row + .row + .row + .row {
    display: none;
}

This should work even in IE7.
Updated fiddle

Also, like Giovanni's solution, something like this could also work.

.container > .row:nth-child(3) ~ .row {
    /* this rule targets the rows after the 3rd .row */
    display: none;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!