css3分栏

效果正解:

如上图所示的分栏效果,如果用css+div那写起来着实要费些事,css3为我们提供了分栏的属性,实现上图很轻松。

一、语法:

column-[<length>|auto]  定义每栏的宽度
column-span : none | all   none:只在本栏中显示;all:横跨所有栏目并定位在栏目的Z轴之上
column-gap : normal | <length>  定义两栏之间的间距距离 
column-count : auto | 整数  可以定义栏目的数目
column-rule : color(色值) width(宽度) style(线条样式) 分栏中的分割线的颜色宽度及样式的设定

其中要注意的是:

1、column-span只对块属性标签有作用。

2、栏宽度与栏数有冲突,如果设置栏宽度后,设置再多的栏数都无意义。

3、栏的分割线类似于border属性,所以,它可以单独的取值color、width、style样式;

如下代码:

column-rule-4px;
column-rule-color:yellow;
column-rule-style:double;

另:style的取值:none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset;

具体事例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body,div,h5,p{
    margin:0;
    padding:0;
}
    div {
        width:600px;
        margin:100px auto;
        font-size: 20px;
        -webkit-column-width:150px;
        -webkit-column-gap:100px;
        -webkit-column-rule:1px red double;
        -webkit-column-rule-width:4px;
        -webkit-column-count:8;

    }
    h5,li,span{
        -webkit-column-span:all;
        border-bottom: 1px blue solid;
    }
    li{
        -webkit-column-width:100px;
        -webkit-column-gap:100px;
        -webkit-column-rule:1px yellow double;
        -webkit-column-rule-width:4px;
        -webkit-column-rule-color:yellow;
        -webkit-column-rule-style:double;
    }
</style>
</head>
<body>
<div>
<h5>标题</h5>    
<ul>
    <li>
        The CSS column-count property allows you to specify the number of columns in your multi-column layout. You can specify your column count to be automatic (i.e. auto) or a specific number (e.g., the number 3 for a 3 column layout).
You can also use the columns property to set the width and column count at once.
    </li>
</ul>
<p>

    11月25日早上7点多,浙江省金华市区后城里街和迪耳路交叉口的非机动车道上,一位老人突然一个踉跄,脸朝下摔倒在地,伤势不明。当时正是早高峰,来来往往的行人和车辆很多。看见老人摔倒,有些人径直走开,也有不少人停了下来。可是,停下来的人你看看我,我看看你,谁也不敢上前扶起老人。葛跃进 摄 图片来源:CFP视觉中国
昨天(25日)早上7点多,金华市区后城里街和迪耳路交叉口的非机动车道上,一位老人突然一个踉跄,脸朝下摔倒在地,伤势不明。
当时正是早高峰,来来往往的行人和车辆很多。看见老人摔倒,有些人径直走开,也有不少人停了下来。
可是,停下来的人你看看我,我看看你,谁也不敢上前扶起老人。
老人大概有80岁,挺瘦弱。摔倒之后,他曾试图自己爬起来,但勉强把上半身撑住,下半身怎么也动不了,只好又趴在了地上。
这时,他的身边已经围了不少人。
一位中年男子说,他的家就住在路边,刚才刷牙时,透过窗户看见老人摔倒过一次,当时老人自己爬了起来。没想到,刷完牙出门,老人又摔倒了。
孙女士恰好骑电瓶车经过,看到老人趴在地上,马上把车停在一边。
“大家都不敢去扶,看老人家摔成那样,我心里急啊。”孙女士说,最近又出了“扶老人被讹”的新闻,老实讲,自己也心有余悸。可遇到这样的事,总要做点什么。
一问,还没有人叫救护车,她就拿出手机拨打了120。
放下电话,孙女士又挡在了老人前面,指挥过往的电瓶车和自行车绕道,以免撞到老人。其他守在边上的市民,也很有默契地围成一个圈,将老人护在中央。
默默守护中,有人跑到街头,叫来了协警。了解情况后,协警将在地上躺了五六分钟的老人,慢慢搀了起来。
这时,救护车也到了路口。
一位先生拔腿就奔了过去,他后来说,老人倒在非机动车道上,当时人多车多,视线不好,他怕救护车一时找不到。
医护人员对老人做了初步诊断,还好,老人只是脸上蹭破了点皮,牙齿出了点血。不过为防万一,医护人员还是将接上了救护车。
看着救护车开远,大家才渐渐散去。两个原本不相识的好心人边走边聊,传来一声叹息:“真心是不敢去扶啊……”文字来源:浙江在线心有余悸。可遇到这样的事,总要做点什么。
一问,还没有人叫救护车,她就拿出手机拨打了120。
放下电话,孙女士又挡在了老人前面,指挥过往的电瓶车和自行车绕道,以免撞到老人。其他守在边上的市民,也很有默契地围成一个圈,将老人护在中央。
默默守护中,有人跑到街头,叫来了协警。了解情况后,协警将在地上躺了五六分钟的老人,慢慢搀了起来。<ul>
    <li>
        The CSS column-count property allows you to specify the number of columns in your multi-column layout. You can specify your column count to be automatic (i.e. auto) or a specific number (e.g., the number 3 for a 3 column layout).
You can also use the columns property to set the width and column count at once.
    </li>
</ul>
这时,救护车也到了路口。
一位先生拔腿就奔了过去,他后来说,老人倒在非机动车道上,当时人多车多,视线不好,他怕救护车一时找不到。
<span>
        The CSS column-count property allows you to specify the number of columns in your multi-column layout. You can specify your column count to be automatic (i.e. auto) or a specific number (e.g., the number 3 for a 3 column layout).
You can also use the columns property to set the width and column count at once.
    </span>
医护人员对老人做了初步诊断,还好,老人只是脸上蹭破了点皮,牙齿出了点血。不过为防万一,医护人员还是将接上了救护车。
看着救护车开远,大家才渐渐散去。两个原本不相识的好心人边走边聊,传来一声叹息:“真心是不敢去扶啊……”文字来源:浙江在线

</p>
<ul>
    <li>
        The CSS column-count property allows you to specify the number of columns in your multi-column layout. You can specify your column count to be automatic (i.e. auto) or a specific number (e.g., the number 3 for a 3 column layout).
You can also use the columns property to set the width and column count at once.
    </li>
</ul>
</div>
</body>
</html>

展现效果

 参考资料:W3CHTML

原文地址:https://www.cnblogs.com/langli/p/3443785.html