2017-07-26 48 views
0

我是webDevelopment.的新手在發佈之前,我已經經歷了所有的答案,但是他們都沒有爲我工作。所以,我在問這個問題。我有一張桌子,我添加了修復標題在響應表中angularjs

overflow-y:scroll; 
height:100px; 

使用此我正在滾動條,但我的表頭不固定。所以,任何人都可以幫助我呢?

<div class="col-xs-12 col-md-12 nopadding"> 
    <div class="table-responsive"> 
     <table class="table table-striped table-bordered col-xs-12 col-lg-12"> 
      <thead class="text-center text-info text-capitalize"> 
      <th class="text-center">Sr.No.</th> 
      <th class="text-center">Document</th> 
      <th class="text-center">Score</th> 
      <th class="text-center">Actions</th> 
      </thead> 
      <tr ng-repeat="file in processResumeFiles"> 
       <td class="text-center">{{ file.id}}</td> 
       <td class="view-orphan uploadResumeTableCellOverFlow"> 
        {{ file.attributes.name}} 
       </td> 
       <td class="text-center">{{file.totalScore}}</td> 
       <td class="text-center"> 
        <button class="btn btn-labeled btn-info" title="click to see" ng-disabled="!file.attributes.isUploadedDocument" data-ng-click="somemethod($index)"> 
         <i class="fa fa-eye" aria-hidden="true"></i> 
        </button> 
        <button class="btn btn-labeled btn-info" title="click to see" ng-disabled="!file.attributes.isCommitted || !file.attributes.isUploadedDocument" data-ng-click="somemethod(file.attributes.name)"> 
         <i class="fa fa-share" aria-hidden="true"></i> 
        </button> 
        <button class="btn btn-labeled btn-info" title="click to see" data-ng-click="somemethod(file.attributes.name)"> 
         <i class="fa fa-trash" aria-hidden="true"></i> 
        </button> 
        <button class="btn btn-labeled btn-info" title="click to see" ng-disabled="!file.attributes.isCommitted || !file.attributes.isUploadedDocument" data-ng-click="somemethod(file.attributes.name)"> 
         <i class="fa fa-sign-out" aria-hidden="true"></i> 
        </button> 
        <button class="btn btn-labeled btn-info" title="click to see" ng-disabled="!file.attributes.isCommitted || !isjdDeleted || !jdSelected" 
          data-ng-click="somemethod(file.attributes.name)"> 
         <i class="fa fa-check-square" aria-hidden="true"></i> 
        </button> 
       </td> 
      </tr> 
     </table> 
    </div> 
</div> 
+0

你爲什麼期望它們被修復?你可以做的只是在'tbody'而不是表格元素上設置'overflow-y:scroll',但是這需要元素顯示爲'block' – devqon

+0

因爲在ng-repeat中表格是有超過100個條目,所以我只想爲該表添加一個滾動條。因此,我希望標題應該被修復。 – ganeshk

+0

不能使用溢出-y:在tbody上滾動 – ganeshk

回答

0

你可以試試這個:

.table-fixed thead { 
    width: 97%; 
} 
.table-fixed tbody { 
    height: 230px; 
    overflow-y: auto; 
    width: 100%; 
} 
.table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th { 
    display: block; 
} 
.table-fixed tbody td, .table-fixed thead > tr> th { 
    float: left; 
    border-bottom-width: 0; 
} 
+0

抱歉,但不工作,這也是。 – ganeshk

0

試試這個

table { 
    width: 100%; 
} 

thead, tbody, tr, td, th { display: block; } 

tr:after { 
    content: ' '; 
    display: block; 
    visibility: hidden; 
    clear: both; 
} 

thead th { 
    height: 30px; 
    text-align: left; 
} 

tbody { 
    height: 120px; 
    overflow-y: auto; 
} 

thead { 
    /* fallback */ 
} 


tbody td, thead th { 
    width: 19.2%; 
    float: left; 
} 

您在小提琴看https://jsfiddle.net/zLgzwn56/

+0

在此之後,列標題與數據未對齊此問題正在發生。 – ganeshk

+0

'thead th {'刪除對'text-align'的評論,請檢查更新後的代碼 –

+0

檢查更新提琴https://jsfiddle.net/zLgzwn56/2/ –

0

首先將您的表格元素添加:。

同樣爲了語義上的正確,爲表格上的內容添加tbody(在你的例子中缺少)。

然後將overflow: auto;和高度添加到tbody。看例子:https://codepen.io/tjvantoll/pen/JEKIu

+0

嘿,我用.tableBodyScroll tbody display:block; max-height:300px; overflow-y:scroll; } .tableBodyScroll thead,tbody tr { display:table; 寬度:100%; table-layout:fixed; }這個CSS,現在的問題是與標題與正文content.column標題的對齊與數據錯位。你可以告訴我爲什麼? – ganeshk

+0

很難知道,不看看你目前的HTML - 你可能會錯過一些單元格。用實際的標記創建一個codepen,它可能會更容易幫助。 – ivanji