CSS自学笔记(15):CSS3多列布局

在CSS3中,也新增了一些关于文本布局的几个比较简单的属性。经过这些新增的属性,咱们能够对文本进行简单的排版,就想报纸和杂志那样。html

新增的部分属性,以及浏览器支持状况:web

属性 浏览器支持
column-count IE Firefox(-moz-) Chrome(-webkit-) Safari(-webkit-) Opera
column-gap IE Firefox(-moz-) Chrome(-webkit-) Safari(-webkit-) Opera
column-rule IE Firefox(-moz-) Chrome(-webkit-) Safari(-webkit-) Opera

注:浏览器

  • 在Firefox浏览器中,要加(-moz-)前缀。
  • 在Chrome和Safari浏览器中,要加(-webkit-)前缀。
  • 对于IE浏览器,只支持IE10以及以上版本。

新增的属性以及描述:布局

属性 描述
column-count 定义元素应该被分隔的列数
column-fill 定义列的填充方式
column-gap 定义列之间的间隔距离
column-rule column-rule属性的简写属性,定义列之间的规则
column-rule-color 定义列之间的规则颜色
column-rule-style 定义列之间的规则样式
column-rule-width 定义列之间的规则宽度
column-span 定义元素应该横跨的列数
column-width 定义列的宽度
columns column-width 和 column-count 的简写属性

经过这几个新增属性的定义,我能够对文本进行简单的排版(Firefox浏览器)ui

*{
	-moz-column-count: 3;
	-moz-column-gap: 40px;
	-moz-column-rule: 4px outset #ff0000;"
}

上面的CSS样式是元素中的文本分为3列,列之间的距离为40px,列之间用颜色为#ff0000、宽度为4px的线分开。spa

image

一样,咱们也能够对一些元素中的内容进行排版。htm

例如咱们能够对列表进行排版:blog

image

部分代码为(Firefox浏览器):utf-8

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
ul {
	-moz-column-count: 3;
	-moz-column-gap: 40px;
	-moz-column-rule: 4px outset #ff0000;
}
li {
	background: #0CF;
	border: #069 1px solid;
	display: inline-block;
	width: 150px;
	margin: 5px 0;
}
</style>
</head>
<body>

<ul>
	<li style="height:50px">1</li>
	<li style="height:100px">2</li>
	<li style="height:80px">3</li>
	<li style="height:60px">4</li>
	<li style="height:70px">5</li>
	<li style="height:50px">6</li>
	<li style="height:100px">7</li>
	<li style="height:80px">8</li>
	<li style="height:90px">9</li>
	<li style="height:30px">10</li>
</ul>
</body>
</html>
相关文章
相关标签/搜索