html - 使 div 填充所有剩余/可用宽度

标签 html css width

CSS

#floatright_a {
    background-color: #c0c0c0;
    float: right;
}
#floatright_b {
    background-color: #ffc0ff;
    float: right;
}
#floatright_c {
    background-color: #c0ffc0;
    /*float: right;*/
}

HTML

<div id="floatright_a">A</div>
<div id="floatright_b">B</div>
<div id="floatright_c">C</div>

fiddle

https://jsfiddle.net/0ty3o56u/

在上面的例子中,C 如何将所有剩余的可用空间都移到左边?

最佳答案

#floatright_a {
    background-color: #c0c0c0;
    position:absolute;
    right:0;
    z-index:1;
    right:10px;
}
#floatright_b {
    background-color: #ffc0ff;
    position:absolute;
    right:0;
    z-index:1;
}
#floatright_c {
    background-color: #c0ffc0;
    float: right;
    width:100%;
    position:relative;
    z-index:0;
}
<div id="floatright_c">C</div>
<div id="floatright_a">A</div>
<div id="floatright_b">B</div>

通过定位,您可以将元素放置在彼此之上,这样,您可以让元素 C 填满整个屏幕,并让元素 ab位置在它上面。可悲的是,我没有办法给 div 一个流动的宽度,稍后可能会回来。

关于html - 使 div 填充所有剩余/可用宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28791730/

相关文章:

javascript - 垂直和水平响应图像

javascript - JS AnimationEnd Loop,想在不使用的情况下不断循环;设置间隔/设置超时

html - 如何防止DIV扩展宽度?

html - 我可以在一个 CSS 选择器中同时使用百分比 (100%) 和像素 (-30px)

c# - CSS 类不能应用于 ASPX C# View 引擎上的 EditorFor

html - 如何将此 DIV float 到其他 DIV 旁边?

CSS 更改未在网站上更新

c# - 获取窗体的宽度#

html - Angular 7,Bootstrap Collapse 和 aria-controls 的动态值

javascript - Material UI v5 样式应用于类不适用?