How to prevent column break within an element?

后端 未结 18 2312
刺人心
刺人心 2020-11-22 16:09

Consider the following HTML:

  • Number one
  • Number two
  • &
相关标签:
18条回答
  • 2020-11-22 16:18

    The accepted answer is now two years old and things appear to have changed.

    This article explains the use of the column-break-inside property. I can't say how or why this differs from break-inside, because only the latter appears to be documented in the W3 spec. However, the Chrome and Firefox support the following:

    li {
        -webkit-column-break-inside:avoid;
           -moz-column-break-inside:avoid;
                column-break-inside:avoid;
    }
    
    0 讨论(0)
  • 2020-11-22 16:24

    This works for me in 2015 :

    li {
      -webkit-column-break-inside: avoid;
      /* Chrome, Safari, Opera */
      page-break-inside: avoid;
      /* Firefox */
      break-inside: avoid;
      /* IE 10+ */
    }
    .x {
      -moz-column-count: 3;
      column-count: 3;
      width: 30em;
    }
    <div class='x'>
      <ul>
        <li>Number one</li>
        <li>Number two</li>
        <li>Number three</li>
        <li>Number four is a bit longer</li>
        <li>Number five</li>
      </ul>
    </div>

    0 讨论(0)
  • 2020-11-22 16:24

    The following code works to prevent column breaks inside elements:

    -webkit-column-break-inside: avoid;
    -moz-column-break-inside: avoid;
    -o-column-break-inside: avoid;
    -ms-column-break-inside: avoid;
    column-break-inside: avoid;
    
    0 讨论(0)
  • 2020-11-22 16:25

    Try this:

    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid;
    -webkit-column-break-inside: avoid-column;
    page-break-inside: avoid-column;
    break-inside: avoid-column;
    

    ...worked for me, might work for you.

    0 讨论(0)
  • 2020-11-22 16:26
    <style>
    ul li{display: table;}  
    </style>
    

    works perfectly

    0 讨论(0)
  • 2020-11-22 16:27

    Firefox now supports this:

    page-break-inside: avoid;
    

    This solves the problem of elements breaking across columns.

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