How to prevent column break within an element?

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

Consider the following HTML:

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

    I had the same problem i think and found a solution in this:

    -webkit-column-fill: auto; /* Chrome, Safari, Opera */
    -moz-column-fill: auto; /* Firefox */
    column-fill: auto;  
    

    Working also in FF 38.0.5: http://jsfiddle.net/rkzj8qnv/

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

    I made an update of the actual answer.

    This seems to be working on firefox and chrome: http://jsfiddle.net/gatsbimantico/QJeB7/1/embedded/result/

    .x{
    columns: 5em;
    -webkit-columns: 5em; /* Safari and Chrome */
    -moz-columns: 5em; /* Firefox */
    }
    .x li{
        float:left;
        break-inside: avoid-column;
        -webkit-column-break-inside: avoid;  /* Safari and Chrome */
    }
    

    Note: The float property seems to be the one making the block behaviour.

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

    Adding;

    display: inline-block;
    

    to the child elements will prevent them being split between columns.

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

    In 2019, having this works for me on Chrome, Firefox and Opera (after many other unsuccessful attempts):

    .content {
        margin: 0;
        -webkit-column-break-inside: avoid;
        break-inside: avoid;
        break-inside: avoid-column;
    }
    
    li {
        -webkit-column-break-inside:avoid;
           -moz-column-break-inside:avoid;
                column-break-inside:avoid;
               break-inside: avoid-column;
                 page-break-inside: avoid;
    }
    
    0 讨论(0)
  • 2020-11-22 16:31

    Firefox 26 seems to require

    page-break-inside: avoid;
    

    And Chrome 32 needs

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

    A possible workaround for Firefox is to set the CSS property "display" of the element you don't want to have a break inside to "table". I don't know if it works for the LI tag (you'll probably lose the list -item-style), but it works for the P tag.

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