1
2
3
4
.container {
  width: 200px; // 根据实际情况设置容器的宽度
}

.item {
  width: 50px; // 根据实际情况设置子元素的宽度
  height: 50px; // 根据实际情况设置子元素的高度
  float: right;
}

使用 CSS 中的 float 属性可以将四个 float:right 元素分别放置在两行。

步骤:

  1. 将四个元素包裹在一个父容器中。
  2. 设置容器的宽度和浮动方式,并设置子元素的浮动方式。
  3. 使用 clear 属性将两个元素放在一行,另外两个元素放在下一行。

示例代码:

<div class='container'>
  <div class='item'>1</div>
  <div class='item'>2</div>
  <div class='item'>3</div>
  <div class='item'>4</div>
</div>
.container {
  width: 200px; // 根据实际情况设置容器的宽度
}

.item {
  width: 50px; // 根据实际情况设置子元素的宽度
  height: 50px; // 根据实际情况设置子元素的高度
  float: right;
}

.item:nth-child(1), .item:nth-child(2) {
  clear: both;
}

这样,四个 float:right 元素就会被平均分布在两行中了。

如何将四个 float:right 元素分两行排列

原文地址: https://www.cveoy.top/t/topic/plBM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录