2011-11-22 107 views
4

Richard JP LeGuen在创建滚动html表时向我提供了帮助。唯一的问题是我不希望表格标题与表格行一起滚动。现在它在他的例子中使用span,但如果我在我的表中使用它,它真的会弄乱我的表格标题。我一直在过去的2个小时里尝试把它排序,但我没有这么做,所以我刚刚离开了表格标题。滚动html表时滚动表标题

那么,有什么问题是,有另一种方式可以使用CSS来确保表标题不能滚动下滚动表时滚动?

下面是我的HTML和CSS代码:

<div id="tableWrapper"> 
    <div id="tableScroll"> 
    <table border=1 id="qandatbl" align="center"> 
    <thead> 
    <tr> 
    <th class="col1">Question No</th> 
    <th class="col2">Option Type</th> 
    <th class="col1">Duration</th> 
    <th class="col2">Weight(%)</th> 
    <th class="col1">Answer</th> 
    <th class="col2">Video</th> 
    <th class="col1">Audio</th> 
    <th class="col2">Image</th> 
    </tr> 
    </thead> 
    <tbody> 
     <tr> 
    <td class="qid"><?php echo $i; ?></td> 
    <td class="options"></td> 
    <td class="duration"></td> 
    <td class="weight"></td> 
    <td class="answer"></td> 
    <td class="video"></td> 
    <td class="audio"></td> 
    <td class="image"></td> 
    </tr> 
    </tbody> 
</table> 
</div> 
</div> 

      #qandatbl{ 
       font-size:12px; 
       border-collapse:collapse; 
       margin:0px; 
       text-align:center; 
       margin-left:auto; 
       margin-right:auto; 
       border:1px solid black; 
      } 
      .col1{ 
      background-color:#FCF6CF; 
      } 
      .col2{ 
      background-color:#FEFEF2; 
      } 
       .options{ 
      overflow:hidden; 
      max-width:125px;  
      min-width:125px; 
      background-color:#FCF6CF; 
      border:1px solid black; 
       } 
      .duration{ 
      overflow:hidden; 
      max-width:125px; 
      min-width:125px; 
      background-color:#FEFEF2; 
      border:1px solid black; 
       } 
      .weight{ 
      overflow:hidden; 
      max-width:125px; 
      min-width:125px; 
      background-color:#FCF6CF; 
      border:1px solid black; 
       } 
      .answer{ 
      overflow:hidden; 
      max-width:125px; 
      min-width:125px; 
      background-color:#FEFEF2; 
      border:1px solid black; 
       } 
      .qid{ 
      overflow:hidden; 
      max-width:125px; 
      min-width:125px; 
      background-color:#FEFEF2; 
      border:1px solid black; 
       } 
      .video{ 
      overflow:hidden; 
      max-width:350px; 
      min-width:350px; 
      background-color:#FCF6CF; 
      border:1px solid black; 
       } 
      .audio{ 
      overflow:hidden; 
      max-width:350px; 
      min-width:350px; 
      background-color:#FEFEF2; 
      border:1px solid black; 
       } 
      .image{ 
      overflow:hidden; 
      max-width:350px; 
      min-width:350px; 
      background-color:#FCF6CF; 
      border:1px solid black; 
       } 
      #tableWrapper { 
    position:relative; 
} 
#tableScroll { 
    height:350px; 
    overflow:auto; 
    margin-top:20px; 
} 

回答