简体   繁体   English

3列布局自动中间列宽

[英]3 column layout auto middle col width

I am trying to make a 3 column layout webpage with percentage wrapper width, fixed (pixels) left and right side width and a varying middle column width but i cannot get it to work for the middle column. 我试图制作一个3列布局的网页,其中包含百分比包装宽度,固定(像素)左右宽度和变化的中间列宽度,但是我无法使它适用于中间列。 Here is the source: 来源如下:

html HTML

<aside class="left">
    <span>Categories</span>


</aside>

<section>
    <span>Main</span>

</section>

<aside class="right">
    <span>Test</span>

</aside>

css CSS

* {
    margin: 0px;
    padding: 0px;

}

html, body {
    height: 100%;
    width: 100%;

}

.container {

    height: 100%;
    width: 100%;

}

.container > aside.left {
    float: left;
    width: 197px;
    border-right: black dashed 3px;

}

.container > section {
    float: left;
    width: auto;


}

.container > aside.right {
    float: left;
    background-color: #005f98;
    width: 200px;

}

You could replace your floats with absolutely positioned sidebars: 您可以用绝对定位的侧边栏替换浮子:

<aside class="left">
    <span>C</span>
</aside>

<section>
    <span>M</span>
</section>

<aside class="right">
    <span>T</span>
</aside>

And

.left {
    position: absolute;
    top: 0;
    left: 0;
    width: 50px;
    display: block;
    background: #ffe;
    height: 100%;
}
.right {
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    display: block;
    background: #fef;
    height: 100%;

}
section {
    display: block;
    margin: 0 50px; /* Margin sized to match the sidebars */
    background: #fee;
}

Live: http://jsfiddle.net/ambiguous/puPbu/ 直播: http//jsfiddle.net/ambiguous/puPbu/

The colors and sizes are just to clarify where everything is. 颜色和大小仅是为了阐明所有内容。 If you're going to put a wrapper <div> around the whole thing then you'll want to have position: relative on it to get the absolutely positioned sidebars in the right place. 如果要在整个对象周围放置包装器<div> ,则需要在其上放置position: relative ,以在正确的位置获得绝对定位的侧边栏。

If you don't have to support IE7, this will work : 如果您不必支持IE7, 则可以使用

* {
    margin: 0px;
    padding: 0px;    
}
html, body {
    height: 100%;
    width: 100%;    
}

.container {
    display: table;    
    height: 100%;
    width: 100%;
    min-width: 600px;

}
.container > aside, .container > section {
    display: table-cell;
    width: auto;
}
.container > aside.left {
    width: 197px;
    border-right: black dashed 3px;
}

.container > aside.right {
    background-color: #005f98;
    width: 200px;
}

in CSS3 you can use 在CSS3中,您可以使用

#multicolumn{
    column-count: 3
}

check it on http://jsfiddle.net/ilumin/w7F7c/ http://jsfiddle.net/ilumin/w7F7c/上进行检查

reference: http://www.quirksmode.org/css/multicolumn.html 参考: http : //www.quirksmode.org/css/multicolumn.html

Try setting the widths according to percentages, so for example: 尝试根据百分比设置宽度,例如:

.container > aside.left {
float: left;
width: 31%;
border-right: black dashed 3px;

}

.container > section {
float: left;
width: 31%;


}

.container > aside.right {
float: left;
background-color: #005f98;
width: 31%;

}

Thats how i've overcome this problem before. 那就是我以前克服这个问题的方式。

If you specify width and float for the left and right column, the middle column will automatically fill up the gap: 如果为左右列指定widthfloat ,则中间列将自动填充空白:

http://jsfiddle.net/xHnDX/4/ http://jsfiddle.net/xHnDX/4/

As you can see, the content div actually overlaps the side divs, although the content will stay between them. 如您所见,内容div实际上与侧div重叠,尽管内容将保留在它们之间。 If you like, you can add an extra container to compensate for the width of the content div as shown here: 如果愿意,可以添加一个额外的容器来补偿content div的宽度,如下所示:

http://jsfiddle.net/YauQc/ http://jsfiddle.net/YauQc/

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

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