html - Flexbox/Float - 2 1 2 布局

标签 html css flexbox

我正在尝试使用 Flexbox 或 float 创建 2 1 2 布局,如添加到此问题的图像所示。有没有什么方法可以仅使用有序的元素列表成功地做到这一点?

<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

enter image description here

1,2,4,5 的大小相同,3 的宽度与其他 block 相同。

我正在尝试使用 Flexbox 来完成此操作,但我似乎无法获得 2 under 1 和 5 under 4。

最佳答案

你可以用 flex-direction: columnflex-wrap: wrap 来做到这一点,但我认为你必须设置 fixed height on parent

body, html, ul {
  margin: 0;
  padding: 0;
}
* {
  box-sizing: border-box;
}
ul {
  display: flex;
  height: 100vh; 
  list-style-type: none;
  flex-direction: column;
  flex-wrap: wrap;
}
li {
  flex: 0 0 50%;
  border: 1px solid black;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 50px;
}
li:nth-child(3) {
  flex: 0 0 100%;
}
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

关于html - Flexbox/Float - 2 1 2 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36724124/

相关文章:

javascript - 淡入内容和淡出当前 Div?

css - 在 flex 表中对齐行高

javascript - 像滚动行为一样聊天(ReactJs)

iphone - iPhone 中的自动旋转问题(纵向到横向)

javascript - 重新加载页面而不发布

css - SWF 全宽响应

css - 带有滚动部分的 Flexbox,它有一个粘性工具栏

html - CSS 颜色在 Windows Phone 8.1 的 IE 中不显示(在其他地方工作)

css - 文字装饰 :none; doesn't work for a simple example

android - 横向滑动过渡滚动