Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
How to center a table in html/js

Hello i have this button that shows a table.

<input id="toggleVisibilityButton" type="button" value="Button1"/>

and this function for the button

document.getElementById("toggleVisibilityButton").addEventListener("click", function(button) {    
    if (document.getElementById("tabel_in_reparatie").style.display === "none")             
        {document.getElementById("tabel_in_reparatie").style.display = "block";}
   
   else document.getElementById("tabel_in_reparatie").style.display = "none";
});

I want to make the table centered, how can I do that? Note: I tried centering it with this

#tabel_in_reparatie {
    margin-left:auto;
    margin-right:auto;
    font-family: Arial, Helvetica, sans-serif;
    border-collapse: collapse;
}

but it won't work.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The easiest way to center a table is to use a flexbox.

.flexbox {
  display: flex;
  justify-content: center;
}
td, tr, th {
  border: 4px solid black;
  padding: 10px;
}
<div class="flexbox">
  <table>
    <tr>
      <th>Head1</th>
      <th>Head2</th>
    </tr>
    <tr>
      <td>Cell1</td>
      <td>Cell2</td>
    </tr>
    <tr>
      <td>Cell1</td>
      <td>Cell2</td>
    </tr>
  </table>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda