"middle"div 的 CSS 问题不会环绕其内容

标签 css html

Here (及下方)您可以看到一个问题,即“中间”div 不会包装其内容。我试图让它自动包装表格的全部内容,所以四周都有一个整洁的白色 10 像素填充边框。我已经尝试了我能想到的一切,尝试显示模式、 float 、清除、溢出……但似乎没有任何效果。谁能看出我哪里出错了?

#outer {
    height : 200px;
    width : 200px;
    background : red;
    overflow : auto;
    padding : 10px;
}
#middle {
    background : white;
    padding : 10px;
}
#inner {
    border : 1px solid purple;
}
td {
    background : cyan;
    padding : 5px;
    border : 1px solid blue;
}
<div id="outer">
  <div id="middle">
    <table id="inner">
      <tr>
        <td>this is some random text</td>
        <td>this is some random text</td>
        <td>this is some random text</td>
        <td>this is some random text</td>
      </tr>
    </table>
  </div>
</div>

最佳答案

添加

display:inline-block;

#middle 定义。

What is the difference between display: inline and display: inline-block?提供有关 inline-block 属性值的更多详细信息。

查看此 updated fiddle .

关于 "middle"div 的 CSS 问题不会环绕其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14497267/

相关文章:

c# - 如何将 "active"css 类添加到链接按钮代码后面

html - 用图像填充剩余的 div 高度

html - CSS :hover is not working in this code

javascript - 通过查找子元素的 data-id 获取父元素的索引

html - 如何禁止在 Magento 中查看文件夹

html - 如何使用 css 相对于绝对定位的输入框定位标签

javascript - 工具提示在带有两个图表的 d3.js 中消失

html - 为什么有些客户端不能从IIS播放一些html5音频?

html - 使用 CSS 使表格的顶部和底部边框可见

html - 将菜单与页面中心对齐