html - 父 div 中子 div 的对齐问题

标签 html css

我有 div(class name:xyz) 在其中插入小的 4 div (class name:ax )。 我需要垂直插入前两个 div,第三个应该水平插入第一个,第四个应该垂直插入第三个。 但是所有的子项都垂直出现在父项的旁边。

.xyz {
  max-height: 450px;
  max-width: 500px;
}

.ax {
  height: 200px;
  width: 200px;
  margin: 0 50px 25px 0;
  background-color: #C0C0C0;
}
<div class="xyz">
  <div class="ax"> </div>
  <div class="ax"> </div>
  <div class="ax"> </div>
  <div class="ax"> </div>
</div>

最佳答案

您可以使用 CSS3 多列布局,在您的情况下为 column-count: 2;,此属性适用于 following browsers

.xyz {
  max-height: 450px;
  max-width: 500px;
  column-count: 2;
  -webkit-column-count: 2;
}

.ax {
  height: 200px;
  width: 200px;
  margin: 0 50px 25px 0;
  background-color: #C0C0C0;
  display:inline-block;
}
<div class="xyz">
  <div class="ax">1</div>
  <div class="ax">2</div>
  <div class="ax">3</div>
  <div class="ax">4</div>
</div>

关于html - 父 div 中子 div 的对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42571909/

相关文章:

javascript - 我必须在 IE 中使用 jquery 框架按两次提交按钮来提交表单

jquery - Pharo Seaside - 如何在 html 中编辑标签后更新数据库条目

html - 如何固定密码输入字段的大小?

css - 如何使 Zurb 电子邮件*无*响应

html - 这个 css 有一个包含 2 行的页面是否正确?

javascript - 在表单中使用 onsubmit 而不是 onchange 时无法获取图像

html - CSS 菜单 - 两行应该删除填充

asp.net - 将网页导出到 Excel 时保留 CSS 样式

jquery - 如何使用纯 CSS 在当前状态下更改图像 onclick?

css - 如何在svg中过渡变换