css - 两个div,一个固定宽度,另一个,其余

标签 css html

我有两个 div 容器。

虽然一个需要特定的宽度,但我需要对其进行调整,以便另一个 div 占据剩余的空间。我有什么办法可以做到这一点吗?

.left {
    float: left;
    width: 83%;
    display: table-cell;
    vertical-align: middle;
    min-height: 50px;
    margin-right: 10px;
    overflow: auto;
}

.right {
    float: right;
    width: 16%;
    text-align: right;
    display: table-cell;
    vertical-align: middle;
    min-height: 50px;
    height: 100%;
    overflow: auto;
}
<div class="left"></div>
<div class="right"></div> <!-- needs to be 250px -->

最佳答案

参见: http://jsfiddle.net/SpSjL/ (调整浏览器的宽度)

HTML:

<div class="right"></div>
<div class="left"></div>

CSS:

.left {
    overflow: hidden;
    min-height: 50px;
    border: 2px dashed #f0f;
}

.right {
    float: right;
    width: 250px;
    min-height: 50px;
    margin-left: 10px;
    border: 2px dashed #00f;
}

您也可以使用 display: table 来实现,这通常是更好的方法:How can I put an input element on the same line as its label?

关于css - 两个div,一个固定宽度,另一个,其余,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6487085/

相关文章:

html - 内联 li 文本相对于背景图像的垂直定位

javascript - getElementById 返回 null

javascript - 单击时如何使内部 div 中的元素覆盖整个外部 div?

html - 如何在框架中制作响应式视频?

jquery - 每四个元素后与 hr 进行画廊设计

javascript - 通过更改边距构建 jquery 幻灯片

html - 对齐div的问题

javascript - 类似文本输入的 HTML 终端

html - 位置 :relative than absolute 的 div 高度变小

html - 对当前节点索引使用 Xpath Count()