html - 使用 css table 将两个 div 并排放置

标签 html css internet-explorer

我想将两个 div 并排放置。右侧 div 的宽度由其内容决定,应与容器 div 的右侧对齐。左侧 div 的宽度应跨越页面的其余部分。

我设法使用以下代码(显然是原始代码的最小化版本)做到了这一点:

<html>
<head>
    <style>
        #container {
            border: 1px solid black;
            display: table;
            width: 1000px;
        }

        #left {
            display: table-cell;
            vertical-align: top;
            width: 100%;
        }
        #right {
            display: table-cell;
            vertical-align: top;
        }
        #image {
            width: 400px;
            height: 300px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="container">
        <div id="left">
            blabla
        </div>
        <div id="right">
            <div id="image">

            </div>
        </div>
    </div>
</body>
</html>

在 chrome 和 firefox 中都能完美运行,但在 IE 中,#right div 显示在左侧下方。

想法是只有#container 和#image 具有显式设置的尺寸。所有其他维度都应该通过某种方式巧妙地对齐从那些维度中推断出来。 display: table-cell css 属性很好地实现了这一点,但似乎没有其他作用......

有人知道解决办法吗?已经有很多“将 div 彼此相邻放置”的问题,但所有解决方案似乎都取决于所有具有固定宽度的 div..

最佳答案

以这种方式更改 CSS:

#left {
    float: left;
    width: 50%;
    padding: 0;
    margin: 0;
}
#right {
    float: right;
    width: 50%;
    padding: 0;
    margin: 0;
}

如果您发现其中的问题,请告诉我们!

关于html - 使用 css table 将两个 div 并排放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12299890/

相关文章:

jquery - 隐藏表列,应用了 colspan ...?

python - 值错误: ('Series lengths must match to compare' when Using Pandas Style

javascript - 如何更改 DIV 的位置,更改其顺序

javascript - 即 : Invalid target element - appending table using innerHTML + string

javascript - 无法使用 javascript 进行自定义验证

javascript - 获取我当前的 URL 并使用 JS 将其插入到 html 中

javascript - 在 'n' 元素上使用纯 javascript 在 CSS 类之间切换

css - html 表单文本框上调整大小控制的 CSS 属性(如果有)是什么?

html - Firefox 加载条件注释中引用的所有 css 文件

javascript - Click() 适用于 IE 但不适用于 Firefox