简体   繁体   English

ul li行但已下令

[英]ul li rows but ordered

I am creating a mega menu in bootstrap, and I wanted to display in the cleanest easiest method, 4 rows ( or more ) but 4 is good, menu items. 我正在引导程序中创建一个大型菜单,我想以最简单的方法显示4行(或更多行),但4行是好的菜单项。

I made a fiddle here http://jsfiddle.net/ozzy/cX5DU/ 我在这里http://jsfiddle.net/ozzy/cX5DU/

The issue seemingly is that the li's are rendered across the page in the order read via html.. 看来问题在于,li是以通过html读取的顺序在页面上呈现的。

Is there a way of ordering the columns, so that the li's display in numeric order vertically ? 有没有一种方法可以对列进行排序,从而使li垂直显示在数字上?

Tagged as jquery because I think jquery may be the saviour here. 标记为jquery是因为我认为jquery可能是这里的救星。

css is: CSS是:

 ul{   width:760px;   margin-bottom:20px;   overflow:hidden;   border-top:1px solid #ccc; } 
 li{   line-height:1.5em;   border-bottom:1px solid #ccc;   float:left;   display:inline; } 
  #double li  { width:50%;} /* 2 col */ 
  #triple li  { width:33.333%; } /* 3 col */ 
  #quad li    { width:25%; } /* 4 col */ 
  #six li     { width:16.666%; } /* 6 col */

I'd keep the source html with a single ul that lists the items in order, then do some shuffling via JS when the DOM is loaded: 我将使用单个ul保留源html,该ul依次列出各项,然后在加载DOM时通过JS进行一些改组:

$(document).ready(function(){    
    var $ul = $("#quad"),
        $lis = $ul.children(),
        i,
        cols = 4,
        rowHeight = Math.ceil($lis.length / cols);

    for (i=0; i+rowHeight<$lis.length; i+=rowHeight)
        $("<ul></ul>").append($lis.slice(i,i+rowHeight))
                      .insertBefore($ul);
});

Demo: http://jsfiddle.net/cX5DU/1/ 演示: http//jsfiddle.net/cX5DU/1/

This creates addition ul elements each with their own portion of the original list. 这将创建附加ul元素,每个元素都具有其自己的原始列表部分。 You'd need to update the CSS to float the uls instead of floating the lis (as shown in the fiddle). 您需要更新CSS以浮动ul,而不是浮动lis(如小提琴所示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM