目录

操作方法 - 混合列布局


了解如何使用 CSS 创建混合列布局网格。


了解如何创建响应式列布局,该布局根据屏幕宽度在 4 列、2 列和全宽列之间变化。

调整大小浏览器窗口查看响应效果:

亲自试一试 »


如何创建混合列布局

步骤1)添加HTML:

示例

<div class="row">
  <div class="column"></div>
  <div class="column"></div>
  <div class="column"></div>
  <div class="column"></div>
</div>


步骤2)添加CSS:

在此示例中,我们将创建一个四列布局,该布局将在宽度小于 900 像素的屏幕上转换为两列。但是,在宽度小于 600 像素的屏幕上,列将堆叠在一起,而不是彼此相邻浮动。

示例

/* Create four equal columns that floats next to each other */
.column {
  float: left;
  width: 25%;
}

/* Clear floats */
.row:after {
  content: "";
  display: table;
   clear: both;
}

/* Responsive layout - makes a two column-layout instead of four columns */
@media screen and (max-width: 900px) {
  .column {
    width: 50%;
  }
}

/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
  }
}
亲自试一试 »

提示:去我们的CSS 网站布局了解有关网站布局的更多信息的教程。

提示:去我们的CSS 响应式网页设计了解有关响应式网页设计和网格的更多信息的教程。