简体   繁体   English

使 div 以动态宽度填充父 div 的剩余水平空间

[英]Make a div fill the remaining horizontal space of a parent div with a dynamic width

I'm trying to make a div fill the remaining horizontal space of a parent div which has an dynamic width (based on screen width).我试图让一个 div 填充具有动态宽度(基于屏幕宽度)的父 div 的剩余水平空间。

How can I achieve this with pure CSS?如何使用纯 CSS 实现这一点? What I try to achieve is shown in the picture below ('Fillable space').我试图实现的目标如下图所示(“可填充空间”)。

图像显示我尝试实现的目标

The code for the following example would currently be:以下示例的代码目前为:

#wrap {
    width: 100%;
    float: left;

    #container {
        width: 100%;
        padding: 0px 30px;

        #static-div {
            width: 60px;
            height: 60px;
        }

        #fillable-space {
            /* What would my code be to fill the remaining space? */
        }
    }
}

Thanks in regards谢谢你的问候

i would use我会用

width: calc( 100% - 60px );
float:left;

like i did in this fiddle: http://jsfiddle.net/74ovL80s/就像我在这个小提琴中所做的那样: http : //jsfiddle.net/74ovL80s/

and if you need to support legacy browsers look here to see if they support the calc function: http://caniuse.com/#feat=calc如果您需要支持旧版浏览器,请查看它们是否支持 calc 功能: http : //caniuse.com/#feat=calc

If you need to support browsers that doesn't support css calc such as IE8, you can do like this.如果你需要支持IE8等不支持css calc的浏览器,你可以这样做。

 #wrap { height: 100px; width: 100%; } #container { width: 80%; padding: 0px 30px; height: 70px; background: grey; } #static-div { width: 60px; height: 60px; background: red; float: left; } #fillable-space { height: 60px; background: blue; margin-right: 60px; }
 <div id="wrap"> <div id="container"> <div id="static-div"> </div> <div id="fillable-space"> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM