Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!