2011-11-14 28 views
1

我有以下代碼:我怎樣才能讓我的顯示器:表; DIV填充包含它的DIV的橫向寬度?

<div class="rep_tb0" style="width: 100%"> 
    <div class="rep_tr0" style="width: 100%"> 
     <div class="rep_td0" style="width: 100%" id="ActivityLog">Activity Log</div> 
    </div> 
</div> 

.rep_tb0 {display: table; } 
.rep_tb0 {padding: 5px;} 
.rep_tb0 {border-collapse:collapse; } 
.rep_tr0 {display: table-row;} 
.rep_td0 {display: table-cell; padding: 5px; vertical-align:top; } 
.rep_td0 {border: 1px solid #666; } 

我想是有字的活動日誌,以水平方向延伸,以填補包含它的DIV表。請注意,DIV有一個寬度設置,但它可能很容易改變。正如你所看到的,我嘗試在三個地方設置寬度,但都沒有工作。

如何在不設置像素寬度的情況下水平填充區域。

請不要忘記我正在使用display:table;這些不是正常的DIV :-)

+0

你爲什麼需要這些表相關的'display'值? –

+0

當我測試這個代碼時,「rep_td0」佔據了整個寬度,就像它應該做的那樣。你正在使用哪種瀏覽器?你確定你不需要桌子嗎?一切都好,如果它是用來顯示一些數據..! – MatTheCat

+0

它正在顯示數據。 –

回答

1

我通常做一個我想要的大小和相對位置的容器;並與絕對值,像這樣內部的div:

<div id="container"> 
    <div id="content">Content</div> 
</div> 

,那麼Css會是這個樣子:

#container{ 
    width:70%; 
    min-width:600px; 
    height: 600px; 
    background:#000; 
    border:medium; 
    border-color:#CCC; 
    border-radius:10px; 
    display:block; 
} 
#content{ 
    position:absolute; 
    display:block; 
    top:0; 
    left:0; 
    width:100%; 
    height:100%; 
} 
-1

我會嘗試兩件事。擺脫rep_td0 div中的硬編碼width:100%,然後在沒有任何寬度的情況下在css中執行margin:0px auto。如果這不起作用,嘗試給reptb0 div用像素而不是百分比的寬度,併爲reptd0 div執行相同的操作。

相關問題