html - 两列布局,左侧为流体,右侧为剩余宽度

标签 html css

我需要类似于 this 的东西和 this .但是我希望右列不是固定大小,而是可变大小。是否可以?

–––––––––––––––––––––––––––––––––––––––––––––––––––––––
|some text|stretch to fill the remaining space        | <- viewport
–––––––––––––––––––––––––––––––––––––––––––––––––––––––

最佳答案

这是float 解决方案。您可以为.one 列设置一个固定的width,或者保持原样,让内容来决定。并将 overflow: auto;overflow: hidden; 设置为 .two 列。

.one {
    float: left;
    background: aqua;
}
.two {
    overflow: auto;
    background: yellow;
}
<div class="one">hello</div>
<div class="two">world</div>

flexbox 解决方案。关键是将 flex: 1; 又名 flex-grow: 1; 设置为动态宽度列。关注this查看浏览器支持表。

body {
    display: flex;
}
.one {
    background: aqua;
}
.two {
    flex: 1;
    background: yellow;
}
<div class="one">hello</div>
<div class="two">world</div>

关于html - 两列布局,左侧为流体,右侧为剩余宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31600709/

相关文章:

html - 当提供非零无单位值(例如,底部)时,固定定位如何工作?

javascript - 触发点击事件时选择父项?

html - 输入元素大于指定

HTML/CSS : Display image in semicircle in top of modal box

html - 如何删除由内联 block <a> 元素上的源代码中的换行符创建的不可见边距

javascript - 单击时输出字段和按钮消失

jquery - 手机上的全屏 Fancybox 允许用户点击

html - 无法将第二个 div float 到第一个 div 的右侧?

html - 如何在html中的图像上添加 Logo 和菜单

javascript - 用 blob 替换 div 背景图像 - jQuery/CSS