2012-11-03 48 views
4

我已經創建了兩個div並使用css內聯屬性左右對齊,問題是我無法設置寬度和高度百分比(不是像素值),我已經看到了這個問題的一些辦法,但我沒有得到解決呢,如何水平對齊兩個div面板

這就是我想要的:enter image description here

這裏是一個小提琴:http://jsfiddle.net/6JgNu/(我用的像素值來設置高度而不是百分比)。請用百分比值的高度更新它。

下面是代碼:

<style type="text/css"> 
.left-panel 
{   
    background-color:#ccc; 
    width:10%; 
    height:100px;    
} 
.right-panel 
{   
    background-color:Gray; 
    width:90%; 
    height:100px; 
} 

第一板 第二面板

任何幫助感激地接受!

回答

4

使用float:left

.left-panel 
{   
    background-color:#ccc; 
    width:10%; 
    height:100px; 
    float:left;    
} 
.right-panel 
{   
    background-color:Gray; 
    width:80%; 
    height:100px; 
    float:left; 
}​ 

演示:http://jsfiddle.net/6JgNu/5/

+0

是否可以設置百分比值的高度 – super

+0

在你的情況下,你必須使用'px'作爲高度。百分比值不起作用。 –

+0

感謝您的幫助 – super

3

只需將float:left;添加到.left-panel即可。希望這有幫助,祝你好運。

0

添加 浮動:左 到div的,它應該工作

0

使用這個CSS

.left-panel 
    {   
     background-color:#ccc; 
     width:10%; 
     height:100px; 
     float:left;   
    } 
    .right-panel 
    {   
     background-color:Gray; 
     width:90%; 
     height:100px; 
     float:left; 
} 
2

使用此:

<style> 
.left-panel 
{   
    background-color:#ccc; 
    width:10%; 
    height:100px; 
    float:left;   
} 
.right-panel 
{   
    background-color:Gray; 
    width:90%; 
    height:100px; 
    float:left; 
} 

</style> 

<div class="left-panel"></div> 
<div class="right-panel"></div>