Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

319
Visualizações
In React, how do I make the tbody of an html table scrollable?

for context I'm using React, Node, Express, Postgres to pull data from a db.

I have an html table in a div that spans across the entire screen. The only way I could succeed in making just the table scrollable I had to add display: block to the header and body sections. The problem was this floated my table to the left so the header and body sections weren't aligned.

Table in question:

<h1>Inventory</h1>
        <div id="Inventory">
            <table className="table" id="InventoryTable">
                <thead id="InventoryHead">
                    <tr>
                        <th>Material</th>
                        <th>Thickness</th>
                        <th>Width</th>
                        <th>Length</th>
                        <th>Quantity</th>
                        <th>Supplier ID</th>
                    </tr>
                </thead>
                <tbody id="InventoryBody">
                    {inventory.map(inventory => (
                            <tr key={inventory.inventory_id}>
                                <td>{inventory.inventory_material}</td>
                                <td>{inventory.inventory_thickness}</td>
                                <td>{inventory.inventory_width}</td>
                                <td>{inventory.inventory_length}</td>
                                <td>{inventory.inventory_quantity}</td>
                                <td>{inventory.supplier_id}</td>
                            </tr>
                        ))}   
                </tbody>
            </table>
            
        </div>

CSS used:

#Inventory {
  overflow: scroll;
  max-height: 300px;
}

Please let me know if there's more info I can provide, thanks!

So far I have tried to use display: block to be able to scroll just the tbody. This worked, but it also broke the table structure. As a workaround I applied overflow: scroll to the div instead, but this isn't ideal because the table header gets scrolled as well.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

just give the table width #InventoryTable { width: 100% }.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda