• CSS3之多列布局columns学习



    CSS3提供了个新属性columns用于多列布局。

    基本属性如下:
    1. columns: column-width column-count

    复合属性:设置对象的列数和每列的宽度。

    /*列数及列宽固定*/
    -moz-columns: 200px 3;
    -webkit-columns: 200px 3;
    columns: 200px 3;
    
    /*列宽固定,根据容器宽度液态分布列数*/
    -moz-columns: 200px;
    -webkit-columns: 200px;
    columns: 200px;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    2. column-width:length | auto

    设置对象的宽度;使用像素表示。

    • auto:根据column-count自定分配宽度。
    /*列宽固定,根据容器宽度液态分布列数*/
    -moz-column-width: 200px;
    -webkit-column-width:  200px;
    column-width: 200px;
    
    • 1
    • 2
    • 3
    • 4
    3. column-count:number | auto

    用来定义对象中的列数,使用数字 1-10表示。

    • auto:根据column-width自定分配宽度。
    /*列数固定,根据容器宽度液态分布列宽*/
    -moz-column-count: 5;
    -webkit-column-count: 5;
    column-count: 5;
    
    • 1
    • 2
    • 3
    • 4
    4. column-gap: normal | length

    设置列之间的像素差距。

    • normal:是默认值,为1em;
    • length:是用来设置列与列之间的间距。
    /* 固定列间隙为40px */
    -moz-column-gap: 40px;
    -webkit-column-gap: 40px;
    column-gap: 40px;
    
    /* 列间隙column-gap: normal;font-size为14px时,列间隙column-gap:normal的计算值也为14px */
    -moz-column-gap: normal;
    -webkit-column-gap: normal;
    column-gap: normal;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    5. column-rule:column-rule-width column-rule-style column-rule-color

    复合属性:设置对象的列与列之间的边框。

    • column-rule-width:设置列中之间的宽度规则(column-rule-width: thin | medium | thick | length;);
    • column-rule-style:设置列中之间的样式规则(column-rule-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset;);
    • column-rule-color:设置列中之间的颜色规则P(column-rule-color: color;)。

    注:column-rule与border同理,这三个属性里,除style不能省略,width和color都可以省略其中之一或都省略,浏览器会使用默认的width或color。

    /* 在列与列之间设置绿色间隔线 */
    -moz-column-rule: 10px solid #090;
    -webkit-column-rule: 10px solid #090;
    column-rule: 10px solid #090;
    
    • 1
    • 2
    • 3
    • 4
    6. column-span:none | all

    设置或检索对象元素是否横跨所有列。

    • 1/none: 元素应跨越一列;
    • all: 该元素应该跨越所有列。

    注:火狐浏览器不支持;

    7. column-fill:auto | balance

    设置对象所有列的高度是否统一。

    • auto: 列高度自适应内容;
    • balance: 所有列的高度以其中最高的一列统一。

    注:主流浏览器都不支持 column-fill 属性。

    8. column-break-before:auto | always | avoid | left | right | page | column | avoid-page | avoid-column

    设置对象之前是否断行。

    • auto: 既不强迫也不禁止在元素之前断行并产生新列;
    • always: 总是在元素之前断行并产生新列;
    • avoid:避免在元素之前断行并产生新列。
    9. column-break-after:auto | always | avoid | left | right | page | column | avoid-page | avoid-column

    设置对象之后是否断行。

    10. column-break-inside:auto | avoid | avoid-page | avoid-column

    设置对象内部是否断行。

    • auto:既不强迫也不禁止在元素内部断行并产生新列;
    • avoid:避免在元素内部断行并产生新列;
    • column-span: none(默认值)|| all,none是不跨越任何列。all 是元素跨越所有列,并定位在列的Z轴之上。
    浏览器支持:

    Internet Explorer 10+Opera 支持 column-width 属性。
    Firefox 支持替代的 -moz-column-width 属性。
    SafariChrome 支持替代的 -webkit-column-width 属性。

    注:Internet Explorer 9 以及更早版本的浏览器不支持 column-width 属性。

    DEMO:
    1.列表瀑布流排版

    在这里插入图片描述

    
    
      
        
        
        测试
        
      
      
        

    111

    222

    333

    444

    555

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    2.文字瀑布流排版

    在这里插入图片描述

    
    
      
        
        
        测试
        
      
      
        

    列数及列宽固定:

    It’s a normal afternoon, sunshine through the window, lazily sprinkled on the desktop. I opened the book Little Prince, in the meantime opening a magical world of tender love.

    Little Prince chiefly tells of a story concerning a lonely prince who is loyal but contrary to love. On the one hand, he overly falls in love with a rose in his planet by reason that her fragrance and beauty are notably charming. On the other hand, conversely, he is too young to know how to love the proud flower. Accordingly, he eventually leaves his rose with tears in eyes. Nevertheless, the pain of separation has long concerned him during his travel along massive planets. In the course of reading the book, I gradually understood the meaning of mature love.

    列宽固定,根据容器宽度液态分布列数:

    First and foremost, what mature love is like: mature love must be reasonable, consistent and candid. Immature love can be disturbing. What invariably occurs is that lovers often feel hurt only because they are improperly loving each other. Immature love makes them inconsistent, or even unreasonable. For instance, it’s immature love that makes the rose pretend to be strong so as to avoid being caught crying when they separate from each other; it’s immature love that makes little prince determined to leave the rose.

    Additionally, immature love makes both little prince and the rose contrary. Little prince is confessional because he ought never to run away from the rose but he does. The rose confides it’s her fault that little prince has not known her love all the while.

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
  • 相关阅读:
    回归预测 | MATLAB实现2-DCNN卷积神经网络多输入单输出回归预测
    手把手教你搭建规范的团队vue项目,包含commitlint,eslint,prettier,husky,commitizen等等
    云安虚拟化应用性能监测系统—应用异常检测
    TikTok大数据解密:社交媒体的秘密洞察
    C后端开发,记录一个关于条件变量的死锁bug
    DevExpress开发WPF应用实现对话框总结
    [python3] 责任链模式
    Sql语句的执行流程
    Flink Paimon0.8 构建 ods层、dw层,
    直流有刷电机编码器测速基于STM32F302R8+X-NUCLEO-IHM07M1
  • 原文地址:https://blog.csdn.net/Mister_SNAIL/article/details/127408959