html - 根据可用空间调整嵌套 div 的大小

标签 html css

我有两个相邻的 div,一个向左浮动,一个向右浮动。

在左侧 float 的 div 中,我还有另外三个嵌套的 div。

我希望嵌套的 div 调整它们的宽度以占用右侧 float div 剩余的可用空间。

我怎样才能让这个奇迹发生?

请参阅此处的代码笔示例:http://codepen.io/bennygill/pen/bZkJyV

这是 HTML:

<div class="outer">
  <div class="inner-left">
    <div class="item">Image and text here. I want all three of these to sit next too each other. But their width should adjust too fill the available space next to the blue "inner-right" content.</div>
    <div class="item">Image and text here. I want all three of these to sit next too each other. But their width should adjust too fill the available space next to the blue "inner-right" content.</div>
    <div class="item">Image and text here. I want all three of these to sit next too each other. But their width should adjust too fill the available space next to the blue "inner-right" content</div>
  </div>
  <div class="inner-right">
    Some other divs and tables go in here. The width of this part will exapand based on the dynamic content it contains.
  </div>
</div>

这是 CSS:

/* Maximum width of container */
.outer {
  width: 1000px;
}

/* Floats div container to the left */
.inner-left {
  float: left;
  display: inline-block;
}

/* Floats div container to the right */
.inner-right {
  float: right;
  width: initial;
  display: inline-block;
  border: 5px solid blue;
}

/* ??? helpe me position these equally in available space ??? */
.item {
  width: 30%; /* This is wrong because they don't adjust to fill the space next to the blue "inner-right" content*/
  text-align: center;
  display: inline-block;
  border: 5px solid red;
}

最佳答案

这是表格的少数合法用例之一。它支持旧浏览器(flexbox 仅 IE10+)并且是完全动态的。

/* Maximum width of container */
.outer {
  width: 1000px;
  display:table;
}

/* Floats div container to the left */
.inner-left {
  vertical-align: -webkit-baseline-middle;
  display: table-cell;
}

/* Floats div container to the right */
.inner-right {
  width: initial;
  display: table-cell;
  border: 5px solid blue;
}

/* ??? helpe me position these equally in available space ??? */
.item {
  width: 30%; /* This is wrong because they don't adjust to fill the space next to the blue "inner-right" content*/
  text-align: center;
  display: inline-block;
  border: 5px solid red;
}
<div class="outer">
  <div class="inner-left">
    <div class="item">Image and text here. I want all three of these to sit next too each other. But their width should adjust too fill the available space next to the blue "inner-right" content.</div>
    <div class="item">Image and text here. I want all three of these to sit next too each other. But their width should adjust too fill the available space next to the blue "inner-right" content.</div>
    <div class="item">Image and text here. I want all three of these to sit next too each other. But their width should adjust too fill the available space next to the blue "inner-right" content</div>
  </div>
  <div class="inner-right">
    Some other divs and tables go in here. The width of this part will exapand based on the dynamic content it contains.
  </div>
</div>

关于html - 根据可用空间调整嵌套 div 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39012002/

相关文章:

html - 为什么 mysql 数据值不会出现在选项菜单中?

css - 居中对齐图像

html - 如何防止内容调整 flex 元素的大小?

CSS Float 位置问题

html - 创建绘图效果

html - 文本框输入高度

php - 可以使从数据库调用的图像成为另一个页面的链接吗?

jquery - 带有一些隐藏选项的选择框不显示任何选项

javascript - 如何让两个div具有相同的borderRadius?

html - 如何停止在 Opencart 中调整图像大小