2014-01-30 31 views
0

我想爲一個具有overflow-x auto的div容器的一部分的div設置一個背景顏色。 我不確定需要應用哪種樣式才能讓div包裝僅在滾動時纔可見的文本。如果我設置了display:block;被設置在div到任何可見:當溢出是auto時,背景顏色不能擴展

<div id="container"> 
     <div class="section"> 
      <div class="title">First</div> 
      <div class="data"> 
       <table class="table"> 
        <tr> 
         <td> 
          First of the rows and all that data 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Second of the rows and all that data 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Third of the rows and all that data 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Fourth of the rows and all that data 
         </td> 
        </tr> 
       </table> 
      </div> 
      <div class="title">Second</div> 
      <div class="data"> 
       <table class="table"> 
        <tr> 
         <td> 
          First of the rows and all that data 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Second of the rows and all that data 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Third of the rows and all that data 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Fourth of the rows and all that data 
         </td> 
        </tr> 
       </table> 
      </div> 
     </div> 
    </div> 

(例如這裏http://jsfiddle.net/u7ah3/1/) 但是,如果我減少#container的寬度(400〜200),然後滾動時水平可以看出,股利不纏繞文本。 我嘗試使用display:inline-block,但當容器寬度大於節塊時,這不起作用。

謝謝。

回答

0

爲什麼不只是風格td s ...?

.table, td { 
    min-width:300px; 
    background:#bbb; 
} 

此外,您應該設置在min-widthsection divs你已經包括在內,如:

.section { 
    min-width:300px; 
} 

JS小提琴http://jsfiddle.net/SinisterSystems/u7ah3/7/

我相信我的理解問題的權利。如果我有什麼不對,請隨時發表評論,我可以進一步提供幫助。