如何调整容器内的桌子高度和宽度,并在<tbody>中添加水平和垂直滚动条以避免溢出?

是的

我在表格标签中添加了调整高度和宽度,并将overflow-xandoverflow-y属性设置为'auto',但是其中的一些似乎无法正常工作并且表格溢出。我已经尝试过实现这一点,但是在我的代码中却不起作用。如果有任何错误或代码中缺少某些内容,请帮助我解决此问题。

<style>
    table {
        max-width: 600px;
        max-height: 400px;
        border-spacing: 0;
        display: block;
    }
    
    tbody {
        overflow-y: auto;
        overflow-x: auto;
    }
    
    th {
        /*display: block;*/
        border: 1px solid #293033;
        position: sticky;
        top: 0;
        text-align: center;
        padding: 8px;
        color: #e9ecef;
        background-color: #1e2324;
        font-weight: 500;
        font-size: 14px;
    }
    
    td {
        background-color: #041230;
        border: 1px solid #293033;
        text-align: center;
        padding: 8px;
        color: #e9ecef;
        min-width: 150px;
        font-size: 13px;
        word-spacing: 2px;
    }
    
    td:nth-child(1) {
        min-width: 50px;
        max-width: 50px;
        font-weight: bold;
        color: #66FCF1;
    }
</style>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="resCSS.css">

<script src="https://rawgit.com/kimmobrunfeldt/progressbar.js/1.0.0/dist/progressbar.js"></script>
<script src="https://cdn.fancygrid.com/fancy.min.js"></script>

<div class="container">
    <table class="tablecolor2">
        <!-- class="tablecolor" -->
        <thead>
            <tr>
                <th>#</th>
                <th>Dummy</th>
                <th>dvfdgdg</th>
                <th>fvfdgfd/fdgdg</th>
                <th>Cdumm</th>
                <th>sdfdgds</th>
                <th>Cd</th>
                <th>Ankjfdksf</th>
                <th>jnknk</th>
                <th>fdfdgdfg</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
            <tr>
                <td>1</td>
                <td>cdfdfsdfs</td>
                <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
                <td>ILorem ipsum, or lipsum as it is sometimes </td>
                <td>known, is </td>
                <td>dummy text used in laying out print, </td>
                <td>N/A</td>
                <td>graphic or web </td>
                <td>N/A</td>
                <td>designs. The passage is attributed to an unknown </td>
            </tr>
        </tbody>
    </table>
</div>

图1表格布局 图2表格布局

罗科·C·布尔扬

基于此答案

  • 不要溢出tbody,而是溢出父对象DIV
  • 不要display: block;在桌子上使用。

/*QuickReset*/*{margin:0;box-sizing:border-box;}

.tableFixHead          { overflow: auto; }
.tableFixHead thead th { position: sticky; top: 0; }

/* CUSTOM SIZE */
.tableFixHead {
  height: 90vh; /* or whatever */
  min-width: 600px;
}

/* OTHER STYLES */
table { border-spacing: 0; }
th,
td {
  text-align: center;
  padding: 8px;
  color: #e9ecef;
  border: 1px solid #293033;
}
th {
  background-color: #1e2324;
  font-weight: 500;
  font-size: 14px;
}
td {
  min-width: 150px;
  background-color: #041230;
  font-size: 13px;
  word-spacing: 2px;
}
td:first-child {
  min-width: 50px;
  font-weight: bold;
  color: #66FCF1;
}
<div class="container tableFixHead">
  <table class="tablecolor2">
    <thead>
      <tr>
        <th>#</th>
        <th>Dummy</th>
        <th>dvfdgdg</th>
        <th>fvfdgfd/fdgdg</th>
        <th>Cdumm</th>
        <th>sdfdgds</th>
        <th>Cd</th>
        <th>Ankjfdksf</th>
        <th>jnknk</th>
        <th>fdfdgdfg</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
      <tr>
        <td>1</td>
        <td>cdfdfsdfs</td>
        <td> ssdfsf dfdsgsdgsdg typesetter in the 15th century who is thought to have scrambledon </td>
        <td>ILorem ipsum, or lipsum as it is sometimes </td>
        <td>known, is </td>
        <td>dummy text used in laying out print, </td>
        <td>N/A</td>
        <td>graphic or web </td>
        <td>N/A</td>
        <td>designs. The passage is attributed to an unknown </td>
      </tr>
    </tbody>
  </table>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Tbody垂直滚动条,没有固定宽度

来自分类Dev

如何避免Flexbox CSS中的水平和垂直滚动条?

来自分类Dev

在Tbody上使垂直和水平滚动

来自分类Dev

当 tbody 设置为其容器的宽度时,我可以在 tbody 溢出时实现水平滚动吗?

来自分类Dev

不管滚动条是否存在,如何使tbody宽度固定?

来自分类Dev

如何显示JList的水平和垂直滚动条?

来自分类Dev

当容器和子项具有自动宽度时如何添加水平滚动条?

来自分类Dev

如果内容超出div中指定的宽度和高度的水平和垂直滚动条

来自分类Dev

滚动 tbody

来自分类Dev

如何在引导表中添加水平滚动条?

来自分类Dev

如何在tbody中遍历td?

来自分类Dev

如何在Winform应用程序中添加水平滚动条以兼容所有屏幕尺寸

来自分类Dev

如何在javascript中的tbody垂直滚动中按百分比设置高度?

来自分类Dev

滚动 tbody 时修复表头和与 tbody 列对齐的 thead 列

来自分类Dev

设置绝对div的宽度会添加水平滚动条

来自分类Dev

情节:如何在情节表达图形上添加水平滚动条?

来自分类Dev

面板中的垂直和水平滚动条

来自分类Dev

如何在Android中以编程方式添加水平和垂直scollview

来自分类Dev

JS改变Tbody的宽度?

来自分类Dev

表 <tbody> 宽度坏了?

来自分类Dev

如何在小部件中添加垂直滚动条?

来自分类Dev

如何在tabcontrol / tabpages中添加垂直滚动条

来自分类Dev

Rmardown:添加水平滚动条以避免输出被截断

来自分类Dev

HTML5中的thead,tfoot和tbody顺序

来自分类Dev

上边距和框阴影在tbody中不起作用

来自分类Dev

如何在tbody中获取所有标签?

来自分类Dev

jQuery如何在tbody中捕获嵌套值?

来自分类Dev

如何在thead和tbody中添加边框,这些边框在可溢出的div中始终可见

来自分类Dev

表格内每个 tbody 的竖线

Related 相关文章

  1. 1

    Tbody垂直滚动条,没有固定宽度

  2. 2

    如何避免Flexbox CSS中的水平和垂直滚动条?

  3. 3

    在Tbody上使垂直和水平滚动

  4. 4

    当 tbody 设置为其容器的宽度时,我可以在 tbody 溢出时实现水平滚动吗?

  5. 5

    不管滚动条是否存在,如何使tbody宽度固定?

  6. 6

    如何显示JList的水平和垂直滚动条?

  7. 7

    当容器和子项具有自动宽度时如何添加水平滚动条?

  8. 8

    如果内容超出div中指定的宽度和高度的水平和垂直滚动条

  9. 9

    滚动 tbody

  10. 10

    如何在引导表中添加水平滚动条?

  11. 11

    如何在tbody中遍历td?

  12. 12

    如何在Winform应用程序中添加水平滚动条以兼容所有屏幕尺寸

  13. 13

    如何在javascript中的tbody垂直滚动中按百分比设置高度?

  14. 14

    滚动 tbody 时修复表头和与 tbody 列对齐的 thead 列

  15. 15

    设置绝对div的宽度会添加水平滚动条

  16. 16

    情节:如何在情节表达图形上添加水平滚动条?

  17. 17

    面板中的垂直和水平滚动条

  18. 18

    如何在Android中以编程方式添加水平和垂直scollview

  19. 19

    JS改变Tbody的宽度?

  20. 20

    表 <tbody> 宽度坏了?

  21. 21

    如何在小部件中添加垂直滚动条?

  22. 22

    如何在tabcontrol / tabpages中添加垂直滚动条

  23. 23

    Rmardown:添加水平滚动条以避免输出被截断

  24. 24

    HTML5中的thead,tfoot和tbody顺序

  25. 25

    上边距和框阴影在tbody中不起作用

  26. 26

    如何在tbody中获取所有标签?

  27. 27

    jQuery如何在tbody中捕获嵌套值?

  28. 28

    如何在thead和tbody中添加边框,这些边框在可溢出的div中始终可见

  29. 29

    表格内每个 tbody 的竖线

热门标签

归档