2011-08-01 39 views
2

我想做一個3列布局網頁百分比包裝寬度,固定(像素)左右側寬度和不同的中間列寬度,但我不能讓它爲中間工作柱。這裏是源:3列布局自動中間列寬度

HTML

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


</aside> 

<section> 
    <span>Main</span> 

</section> 

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

</aside> 

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; 

} 

回答

0

嘗試根據百分比設置寬度,因此,例如:

.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%; 

} 

那如何我已經克服了這個問題之前。

+0

謝謝。這是一個好主意。我調整了一下,現在它工作。 :) – Gasim

+0

然後,也許你可以說我的正確答案哈哈:D 很高興我可以幫助:) –

0

如果指定爲左,右列widthfloat,中間一列會自動填補空白:

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

正如你所看到的,內容DIV實際上重疊側的div,儘管內容將保留在它們之間。如果你願意,你可以添加一個額外的容器,以彌補內容div的寬度,如下所示:

http://jsfiddle.net/YauQc/

+0

我看到只有三個div在HTML和沒有CSS在那個jsfiddle – xec

+0

我做了另一種方式沒有工作。但是我侵入了一點點。 – Gasim

+0

@xec,你說得對。顯然,我沒有保存/更新/正確地分叉它。重建它並更新鏈接。 – GolezTrol

1

您可以用絕對定位的側邊欄取代你的花車:

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

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

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

而且

.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; 
} 

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

顏色和大小隻是爲了澄清一切。如果你打算把<div>包裝在一起,那麼你就需要有position: relative來獲得絕對定位的側邊欄在正確的位置。

1

如果你沒有支持IE7,this will work

* { 
    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; 
}