简体   繁体   English

主div两侧的div,填充了剩余的空间

[英]Divs on both sides of main div, filling the remaining spaces

I'm having trouble wrapping my brain around this one. 我在缠这一个问题时遇到了麻烦。

How would I go about having a fixed width div, margin:auto, and then on both sides of that div have divs that adjusts their width automatically to fill the rest of space? 我将如何设置固定宽度的div,margin:auto,然后在该div的两边都具有自动调整其宽度以填充其余空间的div?

Thanks Appreciate any help 谢谢任何帮助

something like this without any container. 这样的东西没有任何容器。

http://jsfiddle.net/JuG8W/ http://jsfiddle.net/JuG8W/

HTML 的HTML

<div id="left">left</div>
<div id="middle">middle</div>
<div id="right">right</div>

CSS 的CSS

#left{
   float:left;
   width: calc( 50% - 150px );
   background-color:blue;
}
#right{
    float:right;    
    width: calc( 50% - 150px );
    background-color:green;
}
#middle{
   float:left;
   width:300px; 
   margin:0 auto;
   background-color:red;
}

try this jsfiddle it uses simple display property to achieve this layout. 试试这个jsfiddle,它使用简单的display属性来实现这种布局。 It gives you consistent layout even if you scale the width to extreme minimum and you don't have to hard code anything except the width of the center <div> which you can also specify in % . 即使您将宽度缩放到极小值,也不需要硬编码任何东西,除了中心<div>的宽度(也可以用%指定)之外,它都能为您提供一致的布局。

Update 更新资料

First fiddle has center <div> width in % which makes it good for responsive design. 第一个小提琴具有%中心<div>宽度,因此非常适合响应式设计。 This fiddle has center's width fixed (in pixels) 该小提琴的中心宽度固定(以像素为单位)

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

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