【问题标题】:reducing the last 4 containers using nth-child使用 nth-child 减少最后 4 个容器
【发布时间】:2014-03-14 20:37:39
【问题描述】:

我的主页上列出了许多产品,我使用 nth-child 元素来定位最后 4 个以将底部边距减少到 0,但似乎不起作用,我以为它是 nth- child(5), nth-child(6) 等

直播网址(http://bit.ly/1gwfpNF

这是一个sn-p

#layout #categories .box-1:nth-child(5) { margin-bottom: 0px; }
#layout #categories .box-1:nth-child(6) { margin-bottom: 0px; }
#layout #categories .box-1:nth-child(7) { margin-bottom: 0px; }
#layout #categories .box-1:nth-child(8) { margin-bottom: 0px; }

【问题讨论】:

    标签: css


    【解决方案1】:

    就像我昨天学到的,你可以这样做:

    #layout #categories a:nth-last-of-type(-n+4) .box-1 {
        margin-bottom: 0;
    }
    

    nth-child 在父项中计数,因此当您查找 .box 中的 nth-child 时,您的情况总是只有一个子项。

    【讨论】:

    【解决方案2】:

    使用 !important 关键字覆盖如下:

    margin-bottom: 10px !important;

    #layout #categories .box-1 {
    width: 248px;
    float: left;
    margin-bottom: 10px !important;
    margin-top: -140px;
    margin-bottom: 150px;
    }
    

    【讨论】:

    • 请不要过度使用重要的东西。
    • 过度使用是另一回事。我刚才提到了也可以这样做
    猜你喜欢
    • 2013-04-04
    • 2017-11-28
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    相关资源
    最近更新 更多