简体   繁体   English

中心柱流体宽度

[英]Fluid width of center column

I have 3 column layout. 我有3列布局。 I am trying to make the center column with fluid width and the left and right column with fixed width 200px. 我正在尝试使中心列具有流体宽度,而左列和右列具有固定宽度200px。 it looks fine on my screen but when i resize browser window then right column fell down on smaller window size. 它在我的屏幕上看起来不错,但是当我调整浏览器窗口的大小时,右栏就落在了较小的窗口上。

CSS : CSS

#content {
    float: left;
    width: 66.8%;
}
#sidebar-left {
    float: left;
    margin-right: 24px;
    width: 200px;
}
#sidebar-right {
    float: right;
    width: 200px;
}

You don't really need jQuery for this purpose. 为此,您实际上并不需要jQuery You can leverage your layout by using plain old css. 您可以使用普通的旧CSS来利用布局。 The flexible box model would fit this scenario perfectly but I wouldn't suggest it due to the lack of browser support currently. 灵活的盒子模型很适合这种情况,但是由于当前缺乏浏览器支持,我不建议这样做。 I'd suggest placing your boxes in a wrapper with display:table and giving the child boxes a display:table-cell 我建议将您的盒子放在带有display:table的包装中,并给子盒子一个display:table-cell

<div id="wrapper">
    <div class="sidebar left fluid"></div>
    <div class="content fluid"></div>
    <div class="sidebar right fluid"></div>
</div>

And then to display all boxes inside the wrapper element side by side, you can use the following css... 然后要并排显示包装元素内部的所有框,可以使用以下css ...

#wrapper{display:table}
div{height:300px; display:table-cell}
div.content       {  width:100% }
div.sidebar  { width:200px }
.left { float:left }
.right { float:right }
.fluid{display:inline-block}

Here's a JSFiddler Example where I coloured the boxes so you can easily distinguish them 这是一个JSFiddler示例 ,在其中为框上色,以便您可以轻松区分它们

A simple option for this sort of layout would be to go the display: table route: 这种布局的一个简单选择是display: table路线:

.wrap {
    display: table; 
    margin: 0 auto;
}

.wrap > div {
    display: table-cell; 
    height: 200px; 
    background: green;
    width: 66%;
}

#sidebar-left, #sidebar-right {
    width: 200px; 
    background: red;
}

I have sort it with this way. 我已经用这种方式进行了排序。

<div id="wrap">
<div id="sidebar-left"></div>
<div id="sidebar-right"></div>
<div id="content">
<div class="inner"></div>
</div>
</div>

#wrap { overflow:hidden; }
#content {
    padding: 0 200px;
    margin: 0 auto;
}
#content .inner {
    width: 98%;
    margin: 0 auto;
}
#sidebar-left {
    float: left;
    width: 200px
}
#sidebar-right {
    float: right;
    width: 200px
}

Demo : Link 演示链接

HTML: HTML:

<div class="lbar">
    <h1>Left Bar</h1>
    <ul>
        <li>Home</li>
        <li>Development</li>
        <li>Dowload</li>
        <li>Support</li>
    </ul>
</div>
<div class="rbar">
    <h1>Right Bar</h1>
    <ul>
        <li>Peter</li>
        <li>Steve</li>
        <li>Andrew</li>
        <li>Chris</li>
    </ul>
</div>
<div class="middle">
    <h1>Middle</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint</p>
</div>

CSS: CSS:

* {
    font-size: 14px;
}
.lbar { 
    float:left ; 
    width:120px; 
    background-color:yellow;
}
.rbar { 
    float:right ; 
    width:120px; 
    background-color:yellow;
}
.middle { 
    margin-left:120px; 
    margin-right:120px; 
    background-color:gray; 
}

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

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