html - 带滚动和左/右区域的 DIV 布局

标签 html css layout scrollbar

我想实现以下布局:

enter image description here

滚动很简单,它只是一个嵌套的 DIV。我也知道如何添加左边的 40px 区域。问题是:如何添加合适的40px区域?请注意,这两个 40px 区域都在滚动空间之外。

有什么想法吗?

最佳答案

你可以用 Flexbox 来做到这一点:

* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}

.parent {
  display: flex; /* displays the children inline */
}

.parent > .child {
  height: 100px;
}

.parent > .child:nth-child(2) {
  flex: 1; /* stretches to fill the remaining space */
  overflow-x: scroll;
}

.parent > .child:nth-child(2) > div {
  width: 2000px;
}

.parent > .child:first-child,
.parent > .child:nth-child(3) {
  width: 40px;
  background: Lavender;
}
<div class="parent">
  <div class="child"></div>
  <div class="child">
    <div>...WIDE DIV INSIDE THE SECOND CHILD...</div>
  </div>
  <div class="child"></div>
</div>

关于html - 带滚动和左/右区域的 DIV 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47182882/

相关文章:

javascript - 如何在禁用 css 时隐藏 div?

html - 使响应式背景图像在设备间保持一致

android - 具有动态选择的每行布局的 ListView

android - 测量 TextInputLayout 错误容器的高度

CSS block float 问题

jquery - CSS Accordion - 使用 jquery 使 "hover"成为切换,JS 是正确的,但在我的 HTML 中不起作用

html - 如何制作预先设置的自动调整div?

javascript - Div 无法使用 angularjs 正确显示

html - 如何根据表单的状态有条件地格式化测试?

android - 包含布局中的按钮 Onclick 监听器