css - 垂直对齐 div,它们之间的间距相等

标签 css

所以我正在努力用 CSS 实现这个简单的概念,我也搜索了整个互联网但找不到任何东西。我想我只是措辞不正确,所以我正在尝试做的事情的视觉形象是这样的:

enter image description here

顶部的盒子应该放在顶部,底部的盒子应该放在底部。然后它们之间的盒子在顶部和底部应该有相等的间距。这更像是这个答案的垂直版本:https://stackoverflow.com/a/6880421/7150896

最佳答案

您可以为此使用 Flexbox。您只需要设置 flex-direction: columnjustify-content: space-between

body,
html {
  margin: 0;
  padding: 0;
}
.content {
  display: flex;
  height: 250px;
  border: 1px solid black;
  justify-content: space-between;
  flex-direction: column;
  width: 200px;
}
.box {
  background: #0479D9;
  height: 50px;
}
<div class="content">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>

关于css - 垂直对齐 div,它们之间的间距相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40567100/

相关文章:

html -::after 和::before 伪类阻塞 anchor 标签

html - 全屏居中 html5 视频直播

javascript - 在浏览器上滚动时将主菜单渲染到固定的导航栏中

使用 CSS 重复 Html 背景图像

php - 尝试根据我发现的 Flash 元素设计 HTML5 页面

javascript - 同时从两个 div 悬停

css - 使用 ng-view 时的背景大小问题

html - Bootstrap : how to clear images in a gallery?

html - 我的 col-xs-12 在平板电脑和桌面模式下破坏了我的行

html - 对于移动版本,首先重新定位下表的第二列