duanqian2368 2013-03-14 07:00
浏览 38
已采纳

显示多列中的列表项并限制行数

i'm developing a php project in which i'm getting the list from the database and i need to display this data in html in 3 columns and 10 rows and add a button "more" in the end

<?php foreach ($items as $item) { ?>
        <ul>
            <li><a href="<?php echo $item['href']; ?>" >
            <?php echo $item['name']; ?></a></li>
        </ul>
        <?php } ?>

I want it to be displayed as-

item1 item2 item3

item4 item5 item6

.

.

.

.

Maximum 10 rows

last row will be

item item "more" - only if there are more items in the list

"more" is just a link which will take me to some other page

Thanks for any help.

  • 写回答

3条回答 默认 最新

  • dongxianghuan3587 2013-03-14 07:05
    关注

    Add display:inline to li and use pseudo class to break it

    ul{
        margin:0
    }
    li{
        display:inline
    }
    li:nth-child(3n):after {
     content:"\A"; 
     white-space:pre; 
    }
    

    Script (To display more link)

    $('#moreli').toggle($("li").size() > 6);
    

    This enables the more link after 6 list items, you can change the count in the script.

    Note: Reduce the list items to check the effect

    DEMO UPDATED

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器