2010-11-09 79 views
3

如何設置三個水平像這樣排列? 左側寬度:150px,右側寬度:150px,中心一個寬度是其餘像素,中心一個最小寬度將是800px。所有的div都需要一個位置:相對的。 謝謝。css-how to set three parallel DIV?

+0

你有什麼要求,使用div的,一般DIVS建議使用。但是,如果你的情況很簡單,表格可能會快速且容易地創建三列或四列。 – kobe 2010-11-09 17:24:08

+0

相關:http://stackoverflow.com/questions/4116085/how-come-these-divs-will-not-display-on-the-same-line/4116103#4116103 – DaiYoukai 2010-11-09 19:24:28

回答

6

在這裏,我們走了,HTML是如下:

<div id="wrap"> 

    <div class="left"></div> 
    <div class="center"></div> 
    <div class="right"></div> 

    <div class="clearBoth"></div> 

</div> 

,現在下面的CSS:

#wrap { 
width: auto; 
position: relative; 
} 

.left, .right { 
width: 150px; //or use 30% 
float: left; 
} 

.center { 
float: left; 
min-width: 800px; //or use 60% 
width: auto; 
position: relative; 
} 

.clearBoth { 
clear: both; 
} 
+1

感謝Toro,你的代碼更精彩。 – 2010-11-09 23:12:37

+0

對不起,我是一個新人,我不能投票'這個答案對你有幫助'。 – 2010-11-09 23:14:27

+0

別急!重要的是這項工作;) – 2010-11-10 10:12:40

3

如果要定義固定的最大寬度,請使用換行。

.wrap { 
    overflow:hidden; 
    width:1200px; /* Optional */ 
} 

.left { 
    float:left; 
    width:150px; 
} 

.middle { 
    float:left; 
    min-width:800px; 
} 

.right { 
    float:left; 
    width:150px; 
} 

<div class="wrap"> 
    <div class="left">Left</div> 
    <div class="middle">Middle</div> 
    <div class="right">Right</div> 
</div> 
+0

不要忘記寬度:800px; .middle {} – 2010-11-09 17:19:50

+0

啊,對了,忘了他提到了最小寬度。在那裏補充說。 – 2010-11-09 17:21:04

+0

謝謝,在這種情況下,包裝允許設置百分比? .wrap { overflow:hidden; 寬度:100%;/*可選*/ } – 2010-11-09 17:38:34