首页 > web前端 > css教程 > 正文

什么是 CSS 列以及如何填充它?

PHPz
发布: 2023-08-30 15:49:10
转载
1420人浏览过

什么是 css 列以及如何填充它?

我们可以使用各种 CSS 属性来管理网页的列,“column-fill”就是其中之一。 column-fill CSS 属性用于设置内容在多列中的外观。例如,它应该在所有列之间自然流动或平衡。

有时,我们需要在所有列中设置相同的内容,以改善应用程序的用户体验。

语法

用户可以按照以下语法来使用column-fill CSS属性。

column-fill: auto | balance | initial | inherit;
登录后复制

列填充 CSS 属性值

  • auto - 它设置自然流中的内容。例如,它填充第一列,仅将内容发送到第二列。

    立即学习前端免费学习笔记(深入)”;

  • Balance - 用于在所有列中设置相同的内容。

  • Initial - 设置默认值,即“余额”。

  • 继承 - 它从父元素继承列填充属性的值。

示例 1

在下面的示例中,我们定义了两个 div 元素并添加了文本内容。此外,我们还为两个 div 元素设置了固定尺寸。之后,我们将列数设置为 2,将列填充设置为 auto。

在输出中,我们可以观察到它首先填充第一列,然后只填充第二列。如果第一列未完全填充,则内容保留在第一列中。

<html>
<head>
   <style>
      div {
         background-color: red;
         padding: 20px;
         font-size: 1.3rem;
         margin: 20px;
      }
      .javascript {
         column-count: 1;
         column-fill: auto;
         column-gap: 20px;
         column-rule: 1px solid #000;
      }
      .svelte {
         column-count: 2;
         column-fill: auto;
         column-gap: 20px;
         column-rule: 3px dotted blue;
      }
   </style>
</head>
<body>
   <h3> Using the <i> column-fill CSS property </i> to set the content in columns </h3>
   <div class = "javascript">
      JavaScript is a popular programming language used for both front-end and back-end development. It is known for its versatility, allowing developers to create dynamic and interactive websites and applications.
   </div>
   <div class = "svelte">
      Svelte is a web application framework that allows developers to build highly performant and reactive user interfaces. It is designed to optimize the code and minimize the amount of code sent to the browser, resulting in faster load times and better user experience.
      Svelte uses a reactive approach to building user interfaces, meaning that changes in data are automatically reflected in the user interface without needing to write additional code. This can significantly reduce development time and make the code easier to maintain.
   </div>
</body>
</html>
登录后复制

示例 2

在下面的示例中,我们像第一个一样定义了两个 div 元素。之后,第一个 div 元素的列数等于 4,第二个 div 元素的列数等于 3。

此外,我们还为两个 div 元素的“column-fill”属性设置了“balance”值。在输出中,我们可以看到多列之间的内容如何平衡,甚至任何未满的列底部都有空间。

<html>
<head>
   <style>
      div {
         width: 600px;
         height: 200px;
         background-color: green;
         padding: 20px;
         font-size: 1.3rem;
         margin: 20px;
         color: white;
      }
      .python {
         column-count: 4;
         column-fill: balance;
         column-gap: 20px;
         column-rule: 1px solid red;
      }
      .react {
         column-count: 3;
         column-fill: balance;
         column-gap: 20px;
         column-rule: 3px dotted blue;
      }
   </style>
</head>
<body>
   <h3> Using the <i> column-fill CSS property </i> to set the content in columns </h3>
   <div class = "python">
      Python is a versatile programming language widely used for web development, data analysis, machine learning, and
      scientific computing. It has a simple and easy-to-learn syntax, making it a popular choice for beginners.
   </div>
   <div class = "react">
      React is a JavaScript library used for building user interfaces. It allows developers to create reusable UI
      components and efficiently update the DOM as the application state changes. React is widely used for building
      single-page applications and mobile applications.
   </div>
</body>
</html>
登录后复制

用户学会了使用CSS的column-fill属性来设置内容在多列之间的显示方式。建议使用平衡值在“自动”高度的列中平均划分内容。这样我们就可以克服底部空间。

以上就是什么是 CSS 列以及如何填充它?的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号