css实现纵向分列,中间间距相等

方法一:使用网格布局(Grid Layout)

html 复制代码
<!DOCTYPE html>
<html>
<head>
  <style>
    .container {
      height: 100px;
      display: grid;
      grid-template-columns: 2fr 1fr 3fr; /* 自定义每一列的比例 */

      /* 将三个行都设置为平均分配剩余空间 */
      /* grid-template-rows: 1fr 1fr 1fr; */
      /* 设置 3 列,并使每列占据相同的比例 */
      /*grid-template-columns: repeat(3, 1fr); */
      gap: 20px; /* 设置列之间的间距 */
    }
    
    .item {
      background-color: #f1f1f1;
      padding: 20px;
      text-align: center;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="item">项目1</div>
    <div class="item">项目2</div>
    <div class="item">项目3</div>
  </div>
</body>
</html>

方法二:使用多列布局(Multi-column Layout)

html 复制代码
<!DOCTYPE html>
<html>
<head>
  <style>
    .container {
      column-count: 3; /* 设置列数 */
      column-gap: 20px; /* 设置列之间的间距 */
    }
    
    .item {
      background-color: #f1f1f1;
      padding: 20px;
      -webkit-column-break-inside: avoid; /* 防止内容中断到不同列(Webkit 内核浏览器)*/
      page-break-inside: avoid; /* 防止内容中断到不同列(非 Webkit 内核浏览器)*/
      break-inside: avoid; /* 防止内容中断到不同列 */
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="item">项目1</div>
    <div class="item">项目2</div>
    <div class="item">项目3</div>
  </div>
</body>
</html>
相关推荐
用户059540174469 小时前
把记忆存储的回归测试从手工换成 Playwright + GitHub Actions,线上缺陷降低 80%
前端·css
cll_86924189118 小时前
一个好看的Wordpress博客文字css样式
前端·css·ui
三翼鸟数字化技术团队19 小时前
一种前端大屏适配方案
前端·css
muddjsv20 小时前
CSS核心语法精讲:彻底吃透规则结构、选择器与声明规范
前端·css
触底反弹1 天前
一文搞懂 Tailwind CSS 弹性布局:从原理到实战
前端·css·html
小白巨白1 天前
玫瑰花园管理系统:AI识病+3D可视化,一套面向中小型玫瑰种植园的数字化管理工具
css·人工智能·计算机视觉·html5
alexander0682 天前
CSS 类选择器组合
前端·css
HexCIer3 天前
面向未来的原子化 CSS:UnoCSS 核心架构分析与 Tailwind CSS 现状
前端·css·vite
用户059540174463 天前
把大模型记忆回归测试从手工检查换成 Playwright+VCR,误判率从 40% 降到 0
前端·css
breeze jiang3 天前
从零搭建浏览器端 AI 原型:React、WebGPU 与 Tailwind CSS 的一次实践
css·人工智能·react.js