Flex表格未显示超过50行。

huangapple go评论127阅读模式
英文:

Flex table is not showing my more than 50 rows

问题

基本上,我无法使用滚动条向上滚动。这是一个从数据库填充数据的表格,如果我填充得太多,就无法使用滚动条向上滚动。有一些想法吗?
如果有人需要更多信息,我整天都在这里。

HTML

<div class="table-div">
    <table>
        <tr>
            <th>ID</th>
            <th>Nombre</th>
            <th>Cantidad</th>
        </tr>
        <?php 
        foreach($filas->fetch_all(MYSQLI_ASSOC) as $fila){
        ?>
        <tr>
            <td><?=$fila["ID"]?></td>
            <td><?=$fila["Nombre"]?></td>
            <td><?=$fila["Cantidad"]?></td>
        </tr>
        <?php
        }
        ?>
    </table>
</div>

CSS

.table-div{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 50px;
    height: 50vh;
    overflow-y: auto;
    overflow-x: hidden;
}

table{
    min-width: 15vw;
    border: 1px solid white;
    color: white;
    border-collapse: collapse;
}

th{
    text-align: left;
    padding-left: 10px;
    padding-right: 20px;
    border: 1px solid white;
}

td{
    padding-left: 10px;
    padding-right: 20px;
    border: 1px solid white;
}

[![enter image description here][1]][1]


这是您提供的内容的翻译。

<details>
<summary>英文:</summary>

Basically i cant go up with the scrollbar, this is a table that is being filled with data from a data base, if i filled too much i cant go upside with the scrollbar, some ideas?
If someone need more information im here all day i think.

[![enter image description here][1]][1]


HTML

    &lt;div class=&quot;talbe-div&quot;&gt;
        &lt;table&gt;
            &lt;tr&gt;
                &lt;th&gt;ID&lt;/th&gt;
                &lt;th&gt;Nombre&lt;/th&gt;
                &lt;th&gt;Cantidad&lt;/th&gt;
            &lt;/tr&gt;
        &lt;?php 
        foreach($filas-&gt;fetch_all(MYSQLI_ASSOC) as $fila){
            ?&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;?=$fila[&quot;ID&quot;]?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?=$fila[&quot;Nombre&quot;]?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?=$fila[&quot;Cantidad&quot;]?&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;?php
        }

        ?&gt;
        &lt;/table&gt;
    &lt;/div&gt;


CSS

    .table-div{
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        padding: 50px;
        height: 50vh;
        overflow-y: auto;
        overflow-x: hidden;
    }

    table{
        min-width: 15vw;
        border: 1px solid white;
        color: white;
        border-collapse: collapse;
    }

    th{
        text-align: left;
        padding-left: 10px;
        padding-right: 20px;
        border: 1px solid white;
    }

    td{
        padding-left: 10px;
        padding-right: 20px;
        border: 1px solid white;
    }


  [1]: https://i.stack.imgur.com/nhOrY.png

</details>


# 答案1
**得分**: 1

你想要你的表格可滚动,但在任何时候只显示50vh的高度。

一种做法是将所有内容放在一个容器中,该容器的高度为50vh,并滚动该容器,让表格及其弹性外部div拥有它们所需的高度。

以下是一个简单的示例:

```html
<body>
  <div class="container">
    <div class="table-div">
      <table>
        <tr>
          <th>ID</th>
          <th>Nombre</th>
          <th>Cantidad</th>
        </tr>
        <!-- 这里省略了表格的内容,你可以根据需要添加 -->
      </table>
    </div>
  </div>
</body>
<style>
  body {
    background: black;
  }

  .container {
    height: 50vh;
    overflow-y: auto;
  }

  .table-div {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 50px;
    height: 50vh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  table {
    min-width: 15vw;
    border: 1px solid white;
    color: white;
    border-collapse: collapse;
  }

  th {
    text-align: left;
    padding-left: 10px;
    padding-right: 20px;
    border: 1px solid white;
  }

  td {
    padding-left: 10px;
    padding-right: 20px;
    border: 1px solid white;
  }
</style>

请注意,上面的示例中省略了表格的实际内容,你可以根据需要添加表格行和单元格。

英文:

You want your table to be scrollable but to show just 50vh in height at any time.

One way of doing this would be to put everything in a container which has height 50vh and scroll that, letting the table with its flexed outer div have as much height as they need.

Here's a simple example:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;table-div&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Nombre&lt;/th&gt;
&lt;th&gt;Cantidad&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;style&gt;
body {
background: black;
}
.container {
height: 50vh;
overflow-y: auto;
}
.table-div {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 50px;
rheight: 50vh;
overflow-y: auto;
overflow-x: hidden;
}
table {
min-width: 15vw;
border: 1px solid white;
color: white;
border-collapse: collapse;
}
th {
text-align: left;
padding-left: 10px;
padding-right: 20px;
border: 1px solid white;
}
td {
padding-left: 10px;
padding-right: 20px;
border: 1px solid white;
}
&lt;/style&gt;

<!-- end snippet -->

答案2

得分: 0

我遇到了同样的问题。尝试更改高度。如果这不起作用,请提供一个示例输出,我肯定可以帮助您。滚动始终与高度有关。

.table-div {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 50px;
    height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
}
英文:

I had the same issue. Try to change the height. If this doesn't work, please provide an example output and I am sure I can help you. Scroll always has to do with height.

.table-div{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 50px;
height: 80vh;
overflow-y: auto;
overflow-x: hidden;
}

huangapple
  • 本文由 发表于 2023年5月28日 09:25:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定