2014-11-21 106 views
-2

我需要強調的是,這與第一列固定的水平滾動有關,因爲大多數答案都爲我提供了垂直滾動的解決方案。固定第一個標題欄和固定列的表

是否有可能使用純CSS水平滾動的表,但第一個標題和第一列是固定與其餘內容可滾動?

例如,如果我有這個表:

<table> 
    <thead> 
    <tr> 
    <th class="head1">Head 1</th> 
    <th class="head2">Head 2</th> 
    <th class="head2">Head 3</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr> 
    <td class="col1">Col 1</td> 
    <td class="col2">Col 2</td> 
    <td class="col3">Col 3</td> 
    </tr> 
    </tbody> 
</table> 

頭1和COL1總是與滾動其他列中顯示。

+1

已經回答了這裏:https://stackoverflow.com/questions/17067294/html-table-with-100-width-with-vertical-scroll-inside-tbody – Lorenz 2014-11-21 16:47:08

+0

這個回答可以幫助你還有: http://stackoverflow.com/questions/17827908/how-to-make-fixed-header-table-inside-scrollable-div – Adriansyah 2014-11-21 16:49:13

+0

我要求固定的第一列水平滾動,所以這些鏈接都沒有關聯。 – dagda1 2014-11-21 16:59:37

回答

0

This是我所追求的。該示例使用兩個浮動的左表,並將溢出應用於包裝最右邊表格的div。兩個表都包含在一個固定寬度的div中。

<div class="table-container"> 
    <div class="left"> 
    <table> 
     ... 
    </table> 
    </div> 
    <div class="right"> 
    <table> 
     ... 
    </table> 
    </div> 
</div> 

.table-container { 
    position: relative; 
    width: 600px; 
    height: 100%;  
    display: inline-block; 
} 
table { 
    float: left; 
} 

.right { 
    overflow: auto; 
} 
-1
<table > 
    <tr> 
     <th>abc</th> 
     <th>xyz</th> 
    </tr> 

<tr> 
    <td colspan="2"> 
     <div style="height:50px; overflow:scroll;"> 
      <table> 
       <tr> 
        <td>1</td> 
        <td>1</td> 
       </tr> 

       <tr> 
        <td>2</td> 
        <td>2</td> 
       </tr> 

       <tr> 
        <td>3</td> 
        <td>3</td> 
       </tr> 
      </table> 
     </div> 
    </td> 
    </tr> 
    </table> 

請檢查。這可能是工作。

+0

問題增加了橫向滾動不垂直,第一列固定。 – dagda1 2014-11-22 10:32:33

+0

你必須使用overflow-x:scroll屬性進行水平滾動 – 2014-11-22 11:32:19

+0

我正在尋找一個固定的第一列,但我一定是錯誤的,因爲每個人都給我答案的垂直滾動沒有提到任何固定的第一列。 – dagda1 2014-11-22 11:48:17