javascript - 是否可以垂直拆分主要的 25%/50%/25%?

标签 javascript html css

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 4 年前

我有三个 div,我希望它们垂直对齐(如 3 列),并将大小设置为左侧和右侧的 25%,中间的 50%。 此外,我希望它们是无限的和可滚动的,并且每个列都可以根据其他列调整自己的大小。

最佳答案

使用 Flex 盒子非常容易。 检查this awesome guide here

/* Normalize */
html,body {
  height: 100%;
  margin: 0;
  padding: 0;
}

/* Flex power */
.flex-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.flex-container > * {
  width: 100%; /* Not mandatory, but to be sure */
}
.flex-25 {
  height: 25%;
  background: red;
}
.flex-50 {
  height: 50%;
  background: blue;
}
<div class="flex-container">
  <div class="flex-25">
  </div>
  <div class="flex-50">
  </div>
  <div class="flex-25">
  </div>
</div>


编辑

/* Normalize */
html,body {
  height: 100%;
  margin: 0;
  padding: 0;
  line-height: 2em;
}

/* Flex power */
.flex-container {
  display: flex;
  align-items: stretch;
  min-height: 100%;
}
.flex-25 {
  width: 25%;
  background: #333;
  color: #EEE;
}
.flex-50 {
  width: 50%;
  background: #EEE;
}
<div class="flex-container">
  <div class="flex-25">
    <p>Not much here</p>
  </div>
  <div class="flex-50">
    <p>To infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>and infinity<br/>..<br/>..<br/>..<br/>..</p>
  </div>
  <div class="flex-25">
  </div>
</div>

关于javascript - 是否可以垂直拆分主要的 25%/50%/25%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54911634/

上一篇:jquery - 如何只隐藏标签内的文本而不隐藏其他html元素

下一篇:列表项的 HTML/CSS 中心标题

相关文章:

javascript - jQuery 虚拟键盘和向下滑动

css - 文本在 IE7/8 中的透明背景上不抗锯齿

javascript - Joomla 在鼠标悬停时显示子菜单

javascript - 通知 API 和 Web 推送 : Sending messages while page is closed

javascript - 是否有可能捕获 net::ERR_BLOCKED_BY_CLIENT?

javascript - HTML 单选按钮禁用表单提交时的自动选择

html - 缩小时渐变宽度增加?

jquery - 关于实现的完整日历问题

javascript - 将重新渲染限制为功能组件中的特定状态更改

javascript - 仅更改 Framework7 中一个 radio 的非事件颜色?