html - 可滚动的 html 表格

标签 html css twitter-bootstrap

我在使我的 tbody 可滚动时遇到了一些问题

这是我的

.scroll {
overflow: auto;
height: 200px;
display: block;
}

卷轴在tbody上。

这是结果

image fail

关于如何解决这个问题有什么想法吗?

我的 css 的其余部分是标准的 Bootstrap ,类是 table table-hover

谢谢 山姆

最佳答案

我设计了一个轻巧实用的 HTML 表格模板。例如,我使用了里约热内卢奥运会的主题 :) 尽情享受吧!

CSS

<style>
  #grid {
    width: 100%; /* <-- Grid width */
    background-color: yellow; /* Grid background color */
    border: 2px solid lightgray; /* Grid external border color */
    overflow-y: hidden; /* <-- Do not change */
    overflow-x: auto; /* <-- Do not change */
    text-align: left; /* <-- Grid default text alignment */
    font-size: 18px; /* <-- Default text size */
  }
  #grid table {
    width: 100%; /* <-- Do not change */
    border-collapse: collapse; /* <-- Do not change */
  }
  #grid thead tr {
    background-color: yellowgreen; /* <-- Header background color */
    color: white; /* <-- Header font color */
    height: 40px; /* <-- Header height */
  }
  #grid thead, #grid tbody {
    display: block; /* <-- Do not change */
  }
  #grid tbody {
    height: 100px; /* <-- Modify here for grid height */
    overflow-x: hidden; /* <-- Do not change */
    overflow-y: auto; /* <-- Do not change */
    color: black; /* <-- Body font color */
  }
  #grid td, #grid th {
    padding: 8px; /* <-- Grid internal cell padding */
    border: 1px solid lightgray; /* <-- Grid internal border color */
    min-width: 100px; /* <-- Column default size except last one. */
  }
  #grid td:last-child, #grid th:last-child {
    width: 100%; /* <-- Do not change */
  }
  #grid tbody tr td:hover {
    background-color: lightskyblue; /* <-- Cell default color on MouseOver event */
    color: white; /* <-- Cell font color on MouseOver event */
  }
  #grid tbody tr:hover {
    background-color: steelblue; /* <-- Row default color on MouseOver event */
    color: white; /* Row font color on MouseOver event */
  }
</style>

HTML

<div id="grid">
<table>
  <thead>
  <tr>
    <th>Name</td>
    <th>Last name</td>      
    <th>Age</td>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>Jill</td>
    <td>Smith</td>      
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>        
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>      
    <td>50</td>
  </tr>
  </tbody>
</table>
</div>

希望对你有所帮助!
朱利亚诺

关于html - 可滚动的 html 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34863162/

相关文章:

jquery - Bootstrap 词缀重置附加元素?

javascript - 使用 jquery 单击 div 时重定向到 Html.ActionLink

html - 文本中间的行

javascript - 在幻灯片末尾停止 Twitter Bootstrap Carousel

jquery - 如何判断导航栏是否折叠以切换导航栏列表中的元素

javascript - 像 facebook 一样只在通知 div 中滚动,而不是在 body 中滚动

javascript - 复选框 $.change 被自身触发并循环,因为它正在 $.change 内部被修改

javascript - 为什么我的动画 SVG 动画停止改变颜色?

html - div 的 float 在 Chrome 中不起作用,而在其他浏览器中起作用

html - Bootstrap 自定义 Accordion