【问题标题】:Table with flexible fixed header row and scrollable body [duplicate]具有灵活的固定标题行和可滚动正文的表格[重复]
【发布时间】:2016-03-20 00:52:25
【问题描述】:

我想修复第一行和可滚动的主体。当我喜欢像这样修复css时

thead
{
    display: block;
    width: 500px;
}

tbody
{
    display: block;
    width: 500px;
    height: 200px;
    overflow: auto !important;
}

但标题未对齐。列和行未对齐。

th,td
{
    width:50px;
}

我真的不喜欢用 'width' 属性修复 <th> 元素。我希望那样灵活。对那个灵活的固定标题有什么想法吗?

【问题讨论】:

  • 我编辑了您的更新,问题不是发布有效解决方案的地方。如果副本解决了您的问题,那么那里的答案足以让人们知道如何解决此问题。

标签: html css css-tables


【解决方案1】:

尝试在你的风格中使用可能会对你有所帮助

  <style>
html, body{
  margin:0;
  padding:0;
  height:100%;
}
section {
  position: relative;
  border: 1px solid #000;
  padding-top: 37px;
  background: #500;
}
section.positioned {
  position: absolute;
  top:100px;
  left:100px;
  width:800px;
  box-shadow: 0 0 15px #333;
}
.container {
  overflow-y: auto;
}
table {
  border-spacing: 0;
  width:100%;s
}
td + td {
  border-left:1px solid #eee;
}
td, th {
  border-bottom:1px solid #eee;
  background: #ddd;
  color: #000;
  padding: 10px 25px;
}
th {
  height: 0;
  line-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  color: transparent;
  border: none;
  white-space: nowrap;
}
th div{
  position: absolute;
  background: transparent;
  color: #fff;
  padding: 9px 25px;
  top: 0;
  margin-left: -25px;
  line-height: normal;
  border-left: 1px solid #800;
}
th:first-child div{
  border: none;
}
</style>

在html中

<section>
<div class="container">
    <table>
      <thead>
        <tr class="header">
          <th>
            Table attribute name
            <div>Table attribute name</div>
          </th>
          <th>
            Value
            <div>Value</div>
          </th>
          <th>
            Description
            <div>Description</div>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>align</td>
          <td>left, center, right</td>
          <td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of a table according to surrounding text</td>
        </tr>
        <tr>
          <td>bgcolor</td>
          <td>rgb(x,x,x), #xxxxxx, colorname</td>
          <td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the background color for a table</td>
        </tr>
        <tr>
          <td>border</td>
          <td>1,""</td>
          <td>Specifies whether the table cells should have borders or not</td>
        </tr>

      </tbody>
    </table>
  </div>
</section>

【讨论】:

  • 当我在标题中使用绝对值时,内容是不对齐的。它不与表格主体同步
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 2012-01-27
  • 2020-07-07
  • 1970-01-01
  • 2018-03-22
相关资源
最近更新 更多