html - 如何使用剩余宽度?

标签 html css

我想让 div2 在 div1 的右侧水平对齐。 Div2 还应该拉伸(stretch)剩余的宽度,这是一个可变数字(浏览器宽度)。如果我将 div2 宽度设置为绝对宽度 (300px),我会得到正确的对齐方式,但不会消耗剩余的宽度。

应该怎么做?

<div id="1" style="float:left;width:100px">
    the first box
</div>
<div id="2" style="float:left;width:100%">
    the second box
</div>

最佳答案

只要让左边的 float ,第二个会调整它的宽度:

<div id="1" style="float:left;">
    the first box
</div>
<div id="2">
    the second box
</div>

关于html - 如何使用剩余宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15669174/

相关文章:

javascript - React 中 HTML 输入类型数值四舍五入到小数点后两位

javascript - JQuery:如何为动态添加的元素添加一个id?

javascript - 有没有办法重新加载主 GEPlugin 数据库?

html - 为容器设置 CSS 渐变

html - 旋转时的 css 挑战(转换 :rotate) block - width auto

html - 如何将下拉菜单添加到标题导航栏?

jquery - 在 jQuery slideToggle 顶部滑动文本

html - 如何从社交媒体缩略图中排除 Jumbotron 图像?

javascript - 使用 html 或 jquery 或 javascript 在 Whatsapp 中发送图片

html - JS 树 : Change Icon using CSS not accepting the base64 image code