将列表拆分为 X 列

发布于 2024-07-25 11:44:59 字数 578 浏览 2 评论 0原文

问题是将项目列表拆分为可变数量的列,以最大化网页上的显示(注意,它们是从左到右显示的)

如果列表中有 15 个项目,它们会进入一列 如果列表中有 20 个项目,则它们分为两列 如果列表中有 30 个项目,则它们分为两列 最多可以有 8 列来消除水平。 再次滚动

,目标是最大化显示,这解释了上面的轻微不一致 为了确定列数,我可以使用代码的变体 if ( cnt > 100, col = 8 ) else if ( cnt > 60 col = 5 ).... 等等 但我希望有一个更好的公式来确定列数?

输出的形式是

1   2   3   4   5   6   7
8   9   10  11  12  13  14
15  16  17  18  19  20  21
22  23  24  25  26  27  28
29  30  31  32  33  34  35
36  37  38  39  40  41  42
43  44  45  46  47  48  49
50  51  ........

希望问题清楚,如有任何问题请告诉我

The problem is to split a list of items into a variable number of columns to maximize the display on the web page ( note, they are displayed from left to right )

If there are 15 items in the list, they go in one column
if there are 20 items on the list, they go in two columns
if there are 30 items on the list, they go in two columns
there can be max 8 columns to eliminate horiz. scrolling

again, the goal is to maximize the display which accounts for the slight inconsistency above
to determine the # of columns, i could use a variation of the code
if ( cnt > 100, col = 8 ) else if ( cnt > 60 col = 5 ).... etc.
but i hope there's a better formula for determing the column count ?

the output would be of the form

1   2   3   4   5   6   7
8   9   10  11  12  13  14
15  16  17  18  19  20  21
22  23  24  25  26  27  28
29  30  31  32  33  34  35
36  37  38  39  40  41  42
43  44  45  46  47  48  49
50  51  ........

hope the problem is clear, any questions let me know

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时模样 2024-08-01 11:44:59
if count > 15
   cols = count / ITEMS-PER-COL
if cols > 8
   cols = 8

这看起来像吗?

if count > 15
   cols = count / ITEMS-PER-COL
if cols > 8
   cols = 8

does this seem like it ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文