2017-07-26 80 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