简体   繁体   English

HTML列表元素从上到下,然后从左到右

[英]HTML list elements top to bottom, then left to right

I want to do a list of a bunch of items. 我想列出一堆物品。 The height is fixed. 高度是固定的。 So when the list hits the bottom, I want it to wrap around and start a new column. 因此,当列表到达底部时,我希望它环绕起来并开始一个新列。 Is there a way, without knowing the height of each item, to do this in css? 有没有办法在CSS中不知道每个项目的高度? That way the overflow will occur horizontally. 这样,溢出将水平发生。

Check this CSS Trick 检查此CSS技巧

the key is this CSS: 关键是这个CSS:



    ul {
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
    }

It will do exactly what you ask. 它将完全按照您的要求进行。

我想不出一种使用CSS来完成此操作的方法,但是如果您不反对jquery,请查看以下内容: http : //welcome.totheinter.net/columnizer-jquery-plugin/

There is a proposed CSS 3 property for multicolumns (see Quirksmode.org -- Columns for examples using the proprietary properties), but that's not supported in all modern browsers yet. 对于多 ,有一个建议的CSS 3属性(有关专有属性的示例,请参阅Quirksmode.org-列 ),但是并非所有现代浏览器都支持该属性。 Even so, I'm not sure the support is as repeatable across the browsers that do support it as one might hope. 即使这样,我仍不确定该支持在支持它的浏览器中是否可以像人们希望的那样重复。

You could use CSS3 columns. 您可以使用CSS3列。

Here's a fiddle: fiddle and here's the WC3 spec 这里有一个小提琴: 小提琴和这里的WC3规范

why don't you for JavaScript. 为什么不使用JavaScript。 It is simple and compatible with all browser 它简单且与所有浏览器兼容

If you go for CSS3 then IE (The Useless browser) Will not support it. 如果您使用CSS3,则IE(无用浏览器)将不支持它。

I will just give you a hint for javascript 我会给你一个关于javascript的提示

just Calculate Height of your Parent Div 只是计算你的父母的身高

   var height = document.getElementById("ParentDiv").style.height;

Create Child div with same height and add your Divs inside it new child div. 创建具有相同高度的子div,然后在其中添加新的子div。

If height of child div is get exceeds that parent div 如果子div的高度超过该父div

Create another child div and continue the process. 创建另一个子div并继续该过程。

This process is hectic but will support to all browser 此过程比较忙,但将支持所有浏览器

When jQuery-plugins are Good option but I personally feel that if they can do it you can do it. 当jQuery插件是不错的选择,但我个人认为,如果可以,则可以做到。

All the best 祝一切顺利

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

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