2015-10-09 77 views
1

我使用dataTable lib與外部插件,我希望封裝寬度自己調整。如何展開div封裝寬度以適合表內

即使th寬度超過視口,div寬度也不會超過100%。

如何擴展div包裝以適合表寬?

下面是一個例子:

<html> 
<head> 
    <title>test</title> 
    <style> 
    .wrapper { 
     background-color: red; 
     /* width: 8000px; -> don't look for this kind of solution */ 
     width: auto; 
     display: table; 
    } 

    .table { 
     display: table-cell; 
    } 

    .table th { 
     background-color: yellow; 
     border: 1px solid blue; 
     width: 4000px; /* -> note that I can't use the min-width trick because this property is set by an external jQuery plugin */ 
    } 
    </style> 
</head> 
<body> 
    <div class="wrapper"> 
     <table class="table"> 
      <thead> 
       <tr> 
        <th>Hello</th> 
        <th>World</th> 
       </tr> 
      </thead> 
     </table> 
    </div> 
</body> 
</html> 

回答

0

你應該試試這個:

.table { 
    /*width: 4000px;*/ 
    overflow:hidden; 
    width:100%; 
    table-layout: fixed; 
} 
+0

它的工作原理!謝謝 ! – mji