显示不同数量的<li>每行</li>

时间:2015-04-09 01:58:24

标签: html css magento layout html-lists

我想第一排有3个产品和第2排2个产品,这个模式重复。

这是代码

 <ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col">
<?php $_columnCount = $this->getColumnCount(); // value 3 ?>
       <?php $i=0;$k=1;foreach($products as $product ?>
        <li class="item <?php echo ($k==4) || ($k%10==0)? 'big ': '' ?> <?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
         <?php echo $product->getName() ?>
         <?php $k++;?>
        </li>
    <?php endoforeach; ?>
    </ul>

<style>
    .big,.big img
    {
        width: 60% !important;
        height: 278px !important;
    }

</style>

大班适用于4号,10号,14号,20号...... <li>以2个产品排第二排。现在问题是第二行中的第三个<li>需要整行并将下一行<li>下推到下一行。

屏幕截图链接http://i59.tinypic.com/jjr4vc.jpg

这是magento和产品列表scss文件供参考。

任何帮助都将不胜感激。

// This mixin outputs the styles to allow for grids with more than 3 columns
@mixin product-grid($column-count, $container-width, $class-append:"") {

    // Allow this mixin to be used for more specific purposes, such as grids contained within widgets
    @if $class-append != "" {
        $class-append: -#{$class-append};
    }

    /* Config: Columns + flexible gutter */
    $column-gutters: ($column-count) - 1;
    $container: $container-width - (2 * $trim);
    $column-width: ($container - ($column-gutters * $product-column-spacing)) / $column-count;

    /* Undo three-column config */
    .products-grid--max-#{$column-count}-col#{$class-append} > li:nth-child(odd) {
        clear: none;
    }
    .products-grid--max-#{$column-count}-col#{$class-append} > li:nth-child(3n+1) {
        clear: none;
    }
    .products-grid--max-#{$column-count}-col#{$class-append} > li:nth-child(even),
    .products-grid--max-#{$column-count}-col#{$class-append} > li:nth-child(3n) {
        margin-right: percentage($product-column-spacing / $container);
    }

    /* Set column config */
    .products-grid--max-#{$column-count}-col#{$class-append} > li {
        margin-right: percentage($product-column-spacing / $container);
    }
    .products-grid--max-#{$column-count}-col#{$class-append} > li {
        width: percentage($column-width / $container);
        margin-right: percentage($product-column-spacing / $container);
    }
    .products-grid--max-#{$column-count}-col#{$class-append} > li:nth-child(#{$column-count}n+1) {
        clear: left;
    }
    .products-grid--max-#{$column-count}-col#{$class-append} > li:nth-child(#{$column-count}n) {
        margin-right: 0;
    }
}

1 个答案:

答案 0 :(得分:0)

以下脚本为我工作。

<ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col">
<?php $i=0; $k=$_columnCount; foreach ($_productCollection as $_product): ?>
<?php 
$class="";
if($i%$k == 0){ $class='big'; }
$i++;
if($i==$k){ $i=0; $k--; }
if($k == 0) { $k=$_columnCount;$i=0; }
?>
<li class="item <?php echo $class;?><?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<?php echo $product->getName() ?>
</li>
<?php endoforeach; ?>
</ul>

<style>
.big    {
Clear:both;
/*width: 60% !important;
height: 278px !important;*/
}
</style>

希望这对你有所帮助。