Multi-column CSS lists

前端 未结 5 1516
抹茶落季
抹茶落季 2020-12-19 06:26

Is there a way to do re-flowable, multi-column lists, where the list can have list items of varying heights, using only valid CSS? By re-fl

5条回答
  •  庸人自扰
    2020-12-19 07:08

    Original post

    In fact the single command does the trick for me (although it comes in -webkit- and -moz- versions):

    div.wrapper 
    {
        -webkit-column-width: 10em;
        -moz-column-width: 10em;
    }
    

    Here are additional rules to improve readability. Insert the code below and above into an example from A List Apart article (I can paste the whole HTML if somebody clears copyright) and enjoy:

    div.wrapper {       
        border: 2px solid blue;
        -webkit-column-rule: 2px solid blue;
        -moz-column-rule: 2px solid blue;
    }
    
    .wrapper ol {
        margin: 0;
    }
    
    .wrapper br {
        display: none; /* Extra BR is unnecessary there */
    }
    

    Tested: Safari 4 (4528.17), Fx 3.5b4 /Mac.

    Note that on the first encounter of column-width properties some time ago I completely missed the crucial fact that it does rebalancing. Discovered it now at W3C and confirmed with Surfin' Safari.

    Addendum: Fixed number of columns

    As I understand from the clarification, the width of columns should change with the widthof the page, so the commands are more like

    div.wrapper 
    {
        -webkit-column-count: 3;
        -moz-column-count: 3;
    }
    

    Addendum: Vertical scrolling

    Now you say that there should be a vertical scrollbar. Since there is no UI that would do separate scrollbars to the right of each column, I think you have in mind one scrollbar that would scroll the whole multicolumn list. That can be done by wrapping one more div with

    div.morewrap 
    {
         height: 50%; /* whatever you need */
         overflow-y: scroll; 
    }
    

提交回复
热议问题