菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
68
0

css如何将一行平均分成几列?

原创
05/13 14:22
阅读数 909

css如何将一行平均分成几列?

column-count 属性规定元素应该被划分的列数。它的取值可以是number|auto

number:元素内容将被划分的最佳列数。

auto:由其他属性决定列数,比如 "column-width"。

(相关课程推荐:css视频教程

<!DOCTYPE html>
<html>
<head>
<style>
body{
  background: #e4e4e4;
}
.newspaper
{
  -moz-column-count:3; /* Firefox */
  -webkit-column-count:3; /* Safari and Chrome */
  /* 平均分为3列 */
  column-count: 3;
  background: #eee;
}
.item{
  font-size: 16px;
  background: #fff;
}
</style>
</head>
<body>

<p><b>注释:</b>Internet Explorer 不支持 column-count 属性。</p>

<div class="newspaper">
  <div class="item">这是第1列</div>
  <div class="item">这是第2列</div>
  <div class="item">这是第3列</div>
</div>

</body>
</html>

效果:

Snipaste_2019-12-28_13-16-21.jpg

此外,我们还可以设置column-gap,来规定每一列之间的间距。使用Column-rule规定列之间的宽度、样式和颜色。

column-gap:80px;
column-rule:1px outset #ff0000;

Snipaste_2019-12-28_13-22-19.jpg

发表评论

0/200
68 点赞
0 评论
收藏
为你推荐 换一批