Container fix width. Center div dynamic width. want left right divs to fill out remaining width equally

坚强是说给别人听的谎言 提交于 2019-12-02 13:13:27

问题


Have Three columns..Combine width of all three is fixed.. 2nd ( center ) column will have dynamic content.. I need left and right column to fill out remaining space ( container width - center column dynamic width )equally.

Example: http://jsfiddle.net/htKje/

<div class="container">
   <div class="bg"></div>
   <div>Lorem Ipsum</div>
   <div class="bg"></div>
</div>

CSS :
.container { width:500px; }
.bg {backgrould:#CCC; }

回答1:


If you need the left and right columns just for setting the background, then most probably, you don't even need them at all.

Simply setting the background on the .container, giving the same container text-align: center, making the center column inline-block and reseting the background and text-align on it will do the trick.

demo

HTML:

<div class='container'>
    <div class='c'>booooo add remove text here</div>
</div>

CSS:

.container {
    background: #ccc;
    text-align: center;
}
.c {
    display: inline-block;
    background: white;
    text-align: left;
}


来源:https://stackoverflow.com/questions/12474212/container-fix-width-center-div-dynamic-width-want-left-right-divs-to-fill-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!