Prevent element fragmentation in multi-column layout

前端 未结 2 1729
孤街浪徒
孤街浪徒 2021-01-13 13:20

Given this code:



        
相关标签:
2条回答
  • 2021-01-13 14:04

    Probably using -webkit-column-break-after: always; with the FIRST BOX is appropriate.

    <div id="wrapper">
        <div> FIRST BOX: ... </div>
        <div> SECOND BOX: ... </div>
        <div> THIRD BOX: ... </div>
    </div>
    

    And this CSS code:

    #wrapper { 
        border:2px solid red;
        padding:10px;
        width:310px; 
        //height:310px;
        -webkit-column-width:150px; -webkit-column-gap:10px;
        -moz-column-width:150px; -moz-column-gap:10px;
        column-width:150px; column-gap:10px;
    }
    
    #wrapper > div { 
        width:150px;
        background:#ccc;
        margin-bottom:10px;
    }
    #wrapper > div:first-child {
       -webkit-column-break-after: always;
    }
    
    0 讨论(0)
  • 2021-01-13 14:10

    Some experimentation led me to:

    -webkit-column-break-inside: avoid;
    

    http://jsfiddle.net/7TXGS/

    However, it doesn't work in Chrome Stable/Beta. It works in Chrome Canary (and Dev):

    0 讨论(0)
提交回复
热议问题