html - 如何使 3 个元素与左侧的第一个、右上角的第二个和右下角的第三个元素对齐?

标签 html css flexbox

我有以下 html。 <div><item1><item2><item3><div> .这些元素是 div秒。我希望这些元素显示在两列中。 item2 单独位于左列中。在右列中,item1 与顶部对齐,item3 与底部对齐。 这是布局 enter image description here

我如何使用 flexbox 或 float 做到这一点?

最佳答案

您可以使用 flexbox 和 float 来实现,但我可能会为此使用 css-grid。

这样您甚至可以保留当前订单。

.wrapper {
  display: grid;
  grid-template-rows: 1fr 1fr;  /*you can use px, %, auto etc. here*/
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "left-item right-top" "left-item right-bottom";
  
  width: 500px;
  height: 200px;
}

.item2 {
  grid-area: left-item;
  
  background-color: blue;
}

.item1 {
  grid-area: right-top;
  
  background-color: red;
}

.item3 {
  grid-area: right-bottom;
  
  background-color: green;
}
<div class="wrapper">
  <div class="item1"></div>
  <div class="item2"></div>
  <div class="item3"></div>
</div>

不过,我会考虑制作一个不带 css-grid 的(移动)版本作为后备,但由于您现在的布局,我认为它无论如何都适用于台式机/平板电脑?

关于html - 如何使 3 个元素与左侧的第一个、右上角的第二个和右下角的第三个元素对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388861/

相关文章:

html - 显示上方的空白区域 :inline-block divs

css - Bootstrap IE7 模态关闭按钮对齐

html - 为什么 h1 的容器比需要的大很多?

javascript - 具有绝对定位的工具提示元素被溢出的容器剪裁 : auto

html - 如何设置内表的高度

html - 背景图像适合选项?

php不包括一段html代码?

html - 我需要查看 HTML 图像 map 区域

css - HTML 图形中的额外填充

html - 为幻灯片显示内联图像