1

http://jsfiddle.net/jeepstone/UZejB/

当我有 12 个产品,或者实际上是行长的任意倍数 (3) 时,这个网格可以正常工作,但是当我有剩余的项目时,我的边框不起作用。我追求适用于任意数量项目的内部网格。

如果最后一行只有 1 个项目,则有底部或右侧边框。如果有 2 个,则这些项目只有一个右边框。

4

1 回答 1

0

在您的小提琴中,您在最后 3 个元素上有“last3”类。我不确定你是如何生成这个的,但是如果你可以生成这个,你应该能够改为使用模来生成一个简单地称为“lastrow”的类,它只会出现在最后一行中的项目上,而不是总是在最后一行3.有了这个,你可以很容易地告诉它显示某些边框。我还将边框顶部更改为边框底部,这样可以保证您始终有一个您应该使用的边框(例如 10 个项目)

带有新类的 HTML

<section class="products">
    <article class="product-single  cf">1</article><article class="product-single  cf">2</article><article class="product-single  cf">3</article><article class="product-single  cf">4</article><article class="product-single  cf">5</article><article class="product-single  cf">6</article><article class="product-single  cf">7</article><article class="product-single  cf last3 ">8</article><article class="product-single cf">9</article><article class="product-single lastrow cf">10</article><article class="product-single lastrow cf">11</article></section>​

修订的 CSS

* {
 -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -o-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
}
section.products {
width: 100%;        
}
section.products article.product-single  {
    width: 33.3333%;
    padding: 2%;
    display: inline-block;
    vertical-align: top;
    position: relative;
    min-height: 260px;
    border-bottom: 1px solid red;
    border-right: 1px solid red;
    position: relative;
}

section.products article.product-single:nth-child(3n) {
    border-right: none;
}

section.products article.lastrow{
    border-bottom: none;
}

​</p>

这是小提琴。

于 2012-08-31T15:42:48.023 回答