Bootstrap4响应表 - 修复了第一列

时间:2018-04-27 07:37:06

标签: javascript jquery html css bootstrap-4

我正在创建一个包含事件和小时的计划表,因此我需要在表格水平滚动时修复第一列。这将有助于用户更轻松地查看活动时间。我正在使用Bootstrap 4.表格的屏幕截图:http://prntscr.com/japkbc

最好的问候

1 个答案:

答案 0 :(得分:10)

根据我的理解,我没有得到确切含义,我试图在水平滚动时修复第一行。如果您没有找到解决方案,或者我的解决方案不符合您的预期,那么请发表评论。我会尽力帮助你。



table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}
th
{
background-color:black;
color:white;
}
th:first-child, td:first-child
{
  position:sticky;
  left:0px;
 
}
 td:first-child
 {
  background-color:grey;
 }

<table>
  <tr>
     <th>TIME</th>
    <th>Company</th>
    <th>Company</th>
    <th>Company</th>
    <th>Company</th>
    <th>Company</th>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>11:40   </td>
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td> 
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>11:40   </td>
     <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>11:40   </td>
     <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
  <tr>
   <td>11:40   </td>
     <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Island Trading</td>
    <td>Helen Bennett</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>11:40   </td>
     <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Laughing Bacchus Winecellars</td>
    <td>Yoshi Tannamuri</td>
    <td>Canada</td>
  </tr>
  <tr>
    <td>11:40   </td>
     <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
     <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Magazzini Alimentari Riuniti</td>
    <td>Giovanni Rovelli</td>
    <td>Italy</td>
  </tr>
</table>
&#13;
&#13;
&#13;