固定标题和固定列表

2024-02-07

我的固定标题和固定列表有问题。标题是固定的,但列不是。那么我该如何解决这个问题呢?我试图给第一列位置:固定,但它不能正常工作。如果可能的话,不用Javascript。 (我试图从同一主题的早期问题中找到解决方案,但这些都没有帮助我)。这是我的Codepen https://codepen.io/a1503080/pen/LrLezj.

body {
  background-image: url(http://absfreepic.com/absolutely_free_photos/small_photos/green-grass-football-lawn-4020x2261_98957.jpg);
}

h3 {
  margin: auto;
  text-align: center;
  padding: 10px;
  color: white;
}

.table {
  background-color: white;
  margin: auto;
  width: 600px;
  border-collapse: separate;
  display: block;
  overflow-x: scroll;
}

thead,
tbody {
  display: inline-block;
}

tbody {
  overflow-y: scroll;
  overflow-x: hidden;
  max-height: 70px;
  position: relative;
}

th {
  background-color: lightgrey;
}

td,
th {
  min-width: 100px;
  max-width: 100px;
  word-wrap: break-word;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
  <h3>World Cup 2018</h3>

  <table class="table table-bordered">
    <thead>
      <tr>
        <th></th>
        <th colspan="6">Europe</th>
        <th colspan="3">South-America</th>
        <th colspan="2">Asia</th>
      </tr>
      <tr>
        <th>Countries</th>
        <th>Germany</th>
        <th>Spain</th>
        <th>Portugal</th>
        <th>France</th>
        <th>England</th>
        <th>Croatia</th>
        <th>Argentina</th>
        <th>Brazil</th>
        <th>Colombia</th>
        <th>Japan</th>
        <th>Russia</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th>Goalkeeper</th>
        <td>Neuer</td>
        <td>De Gea</td>
        <td>Beto</td>
        <td>Lloris</td>
        <td>Butland</td>
        <td>Subasic</td>
        <td>Caballero</td>
        <td>Alisson</td>
        <td>Ospina</td>
        <td>Kawashima</td>
        <td>Lunev</td>
      </tr>
      <tr>
        <th>Defender</th>
        <td>Boateng</td>
        <td>Ramos</td>
        <td>Pepe</td>
        <td>Varane</td>
        <td>Walker</td>
        <td>Lovren</td>
        <td>Otamendi</td>
        <td>Marcelo</td>
        <td>Sanchez</td>
        <td>Makino</td>
        <td>Granat</td>
      </tr>
      <tr>
        <th>Midfielder</th>
        <td>Kroos</td>
        <td>Iniesta</td>
        <td>Ronaldo</td>
        <td>Tolisso</td>
        <td>Lingard</td>
        <td>Modric</td>
        <td>Messi</td>
        <td>Paulinho</td>
        <td>Rodriguez</td>
        <td>Honda</td>
        <td>Golovin</td>
      </tr>
      <tr>
        <th>Forward</th>
        <td>Gomez</td>
        <td>Asensio</td>
        <td>Quaresma</td>
        <td>Griezmann</td>
        <td>Welbeck</td>
        <td>Perisic</td>
        <td>Dybala</td>
        <td>Neymar</td>
        <td>Bacca</td>
        <td>Osako</td>
        <td>Smolov</td>
      </tr>
    </tbody>
  </table>

body {
  background-image: url(http://absfreepic.com/absolutely_free_photos/small_photos/green-grass-football-lawn-4020x2261_98957.jpg);
}

h3 {
  margin: auto;
  text-align: center;
  padding: 10px;
  color: white;
}

.table {
  background-color: white;
  margin: auto;
  width: 600px;
  border-collapse: separate;
  display: block;
  overflow-x: scroll;
}

thead,
tbody {
  display: inline-block;
}

thead {
  position: sticky;
  top: 1px;
  z-index: 9999;
}

tbody {
  height: 80px;
}

th {
  background-color: lightgrey;
}

td,
th {
  min-width: 100px;
  max-width: 100px;
  word-wrap: break-word;
}

.fixed {
  position: sticky;
  width: 5em;
  left: 0;
  top: auto;
  z-index: 999;
}

td:not(.fixed) {
  z-index: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="conatiner">
  <table class="table table-bordered">
    <thead>
      <tr>
        <th></th>
        <th colspan="6">Europe</th>
        <th colspan="3">South-America</th>
        <th colspan="2">Asia</th>
      </tr>
      <tr>
        <th class="fixed">Countries</th>
        <th>Germany</th>
        <th>Spain</th>
        <th>Portugal</th>
        <th>France</th>
        <th>England</th>
        <th>Croatia</th>
        <th>Argentina</th>
        <th>Brazil</th>
        <th>Colombia</th>
        <th>Japan</th>
        <th>Russia</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th class="fixed">Goalkeeper</th>
        <td>Neuer</td>
        <td>De Gea</td>
        <td>Beto</td>
        <td>Lloris</td>
        <td>Butland</td>
        <td>Subasic</td>
        <td>Caballero</td>
        <td>Alisson</td>
        <td>Ospina</td>
        <td>Kawashima</td>
        <td>Lunev</td>
      </tr>
      <tr>
        <th class="fixed">Defender</th>
        <td>Boateng</td>
        <td>Ramos</td>
        <td>Pepe</td>
        <td>Varane</td>
        <td>Walker</td>
        <td>Lovren</td>
        <td>Otamendi</td>
        <td>Marcelo</td>
        <td>Sanchez</td>
        <td>Makino</td>
        <td>Granat</td>
      </tr>
      <tr>
        <th class="fixed">Midfielder</th>
        <td>Kroos</td>
        <td>Iniesta</td>
        <td>Ronaldo</td>
        <td>Tolisso</td>
        <td>Lingard</td>
        <td>Modric</td>
        <td>Messi</td>
        <td>Paulinho</td>
        <td>Rodriguez</td>
        <td>Honda</td>
        <td>Golovin</td>
      </tr>
      <tr>
        <th class="fixed">Forward</th>
        <td>Gomez</td>
        <td>Asensio</td>
        <td>Quaresma</td>
        <td>Griezmann</td>
        <td>Welbeck</td>
        <td>Perisic</td>
        <td>Dybala</td>
        <td>Neymar</td>
        <td>Bacca</td>
        <td>Osako</td>
        <td>Smolov</td>
      </tr>
    </tbody>
  </table>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

固定标题和固定列表 的相关文章

随机推荐

  • Sifr 和 Javascript 更改样式表(无需刷新页面)

    我目前正在我的网站上使用 Sifr 基本上我的页面顶部有一些彩色块 它们将根据您选择的颜色通过 JavaScript 更改样式表 我想知道如何让 Sifr h1 h2 标签在单击时动态重新加载 无页面刷新 如果可能的话 我尝试在 oncli
  • 将自定义视图引擎添加到“新项目”对话框中?

    当为 MVC3 创建新项目时 我可以选择自定义视图引擎 我可以选择Razor and ASPX 有没有办法添加Spark到下拉列表 简短的回答是 不 不是 长的答案是 是的 但有一个问题 它需要注册表编辑 The New Project D
  • env['warden'] 不适用于 Rails 5

    我按照本指南使用 Websockets 创建聊天功能 https www sitepoint com rails and actioncable adding advanced features https www sitepoint co
  • 在管道内运行消费者

    我需要组合一个消费者和一个管道 以便消费者的输出可以提供管道的输入 我想这可以用这样的组合器来解决 Consumer i m r gt r gt Producer o m r gt Pipe i o m r or this Consumer
  • Kentico中门户模板和ASPX模板的区别

    Kentico 中的门户模板和 ASPX 模板有什么区别 哪个更可取 作为一名 硬核 开发人员和经过认证的 Kentico 培训师 我始终使用并始终推荐使用 Portal Engine 而不是 ASPX 模板 我这么说是因为Portal E
  • 为什么这段带有泛型的代码可以编译?

    这似乎是一个愚蠢的问题 但我现在正在被它绊倒 为什么会这样编译 import java util public class Test public static void main String argv throws Exception
  • ReplayKit 返回错误“RPRecordingErrorFailedToStart”

    我正在尝试将录制功能包含到我的基于 C 的游戏中ReplayKit 我在我的游戏代码中检查iOS版本是否为9 0或以上 如果是 我会调用RecordReplayIOS startRecording 然后 ReplayKit 应该开始录制 由
  • 什么命令显示 Kafka 中分区的所有主题和偏移量?

    我正在寻找一个显示所有主题和分区偏移量的 Kafka 命令 如果是动态的就完美了现在我用java代码来查看这些信息 但是很不方便 Kafka http kafka apache org documentation html附带了一些您可以用
  • 什么时候需要在 TThread 中进行同步?

    我知道你需要synchronize yourprocedure 设置例如标签的文本 但是关于 读取标签的文本 切换 设置标签的启用属性 调用其他标签过程 函数 例如 onclick 事件 当我需要使用时 是否有一个简单的规则可以知道 记住s
  • 谷歌地图最大缩放

    我想设置最大缩放级别以阻止在地图中的某个点之后进行缩放的可能性 var mapa obiekt globalny function dodajMarker opcjeMarkera opcjeMarkera map mapa var mar
  • Jquery UI 可排序 - 在启动事件触发之前执行操作

    我已经在 STACKOVERFLOW 和其他论坛中搜索了我的问题的解决方案 如果我错过了可行的解决方案 请指出它 我的问题 每当在可排序列表中拖动元素 Portlet div 时 我需要在实际拖动过程开始之前执行一些操作 根据我在 STAR
  • 如何在 Tkinter 中禁用(灰显)检查按钮?

    我不知道如何使 Tkinter 变灰Checkbutton 我尝试使用state DISABLED但它不起作用 我收到一条错误消息 tkinter TclError 错误选项 enable 必须是 column columnspan in
  • 如何访问父/兄弟模块方法

    有什么办法可以访问吗baz method inside class Qux没有从一开始就提到模块名称空间 当有很多嵌套模块时 代码看起来不干净 module Foo module Bar module Baz class Qux def s
  • Angular 2 - 使用 ng2-idle 注销

    我的问题是 当单击注销按钮时 ng2 idle 继续工作 为了尝试解决这个问题 我再次将 setIdle 和 setTimeout 函数设置为 1 秒 但是 当用户转移到登录屏幕时 应用程序需要 1 秒才能超时 我想知道在单击调用 logo
  • 如何在 Eclipse 中进行 git merge 压缩

    有时我需要从 Eclipse 合并南瓜 我知道我可以在命令行中完成此操作 但是在 Eclipse 中集成图形选项将非常有用 你知道该怎么做吗 您可以开始一个Egit 中的交互式变基 http wiki eclipse org EGit Us
  • 是否有可靠的工具可以在担任领班时单步执行代码

    我正在寻找一些关于类似于使用 binding pry 的工具的建议 我正在与 foreman 一起在本地提供 Rails 应用程序 并且希望实现相同的功能 将 调试器 放入我的代码中 当进程遇到该问题时 冻结并打开该代码部分中的控制台环境
  • 在 ASP.NET Core MVC 中使用 Tag Helpers 有什么好处

    我刚刚看到一篇关于 ASP NET Core 新功能的好文章 名为标签助手 http stephenwalther com archive 2015 02 24 top 10 changes in asp net 5 and mvc 6 从
  • 挂在 bootstrap 表中的 1000 或 5000 条记录上

    下面的链接给出了很好的例子 http issues wenzhixin net cn bootstrap table 但是 当分页大小从 10 更改为 1000 或 5000 时 浏览器会挂起超过 20 秒或一分钟才能填充网格 数据中的记录
  • 通过绑定新数据来操作元素

    我正在尝试弄清楚如何通过绑定新数据来更新一些 D3 js 元素 我实际上不确定这是否可能 但感觉应该是 首先我创建了四个 SVG 圆圈 并设置cx偏移量作为数据的函数 div div var svg d3 select div contai
  • 固定标题和固定列表

    我的固定标题和固定列表有问题 标题是固定的 但列不是 那么我该如何解决这个问题呢 我试图给第一列位置 固定 但它不能正常工作 如果可能的话 不用Javascript 我试图从同一主题的早期问题中找到解决方案 但这些都没有帮助我 这是我的Co