How to make floating DIV list appear in columns, not rows

前端 未结 5 610
-上瘾入骨i
-上瘾入骨i 2020-12-03 04:24

I have a HTML layout puzzle on my hands. I have a large alphabetical list, generated by my PHP app, and I need to output it on a web page. The markup generated look like thi

5条回答
  •  独厮守ぢ
    2020-12-03 04:57

    Depending on which browsers you need to support, you can use the new CSS3 column-count property.

    With a simple list mark up

    • A
    • B
    • C
    • D

    Use this CSS:

    ul {
        -moz-column-count: 2;
        -moz-column-gap: 20px;
        -webkit-column-count: 2;
        -webkit-column-gap: 20px;
        column-count: 2;
        column-gap: 20px;
    }
    

    Here is a fiddle - although it's not supported in any version of IE yet. To support older browsers there are jQuery solutions, such as Columnizer jQuery Plugin, that you can use as well as, or instead of the CSS3 solution,

提交回复
热议问题