I'm searching for guidance on how to properly align my HTML table in the center. Any assistance

My tables initially appear like this

https://i.sstatic.net/Fm4jc.png

However, when I enter information into them, they end up looking messy like this

https://i.sstatic.net/ZAPPX.png

I currently try to center my tables using relative positioning and pixel values from the top and left, as shown below

   #damagetablemario {
    display:none;
    position:absolute;
    top:700px;
    left:80px;
    border-collapse:collapse;
}
   #damagetablemario2 {
   display:none;
   position:relative;
   top:400px;
   left:110px;
   border-collapse:collapse;
}
   #damagetablemario3 {
   display:none;
   position:relative;
   top:450px;
   left:540px;
   border-collapse:collapse;
   margin-bottom:200px;
}




    <table id = "damagetablemario">
      <tr>
      <th>Neutral</th>
      <th>Forward  Tilt</th>
      <th>Up Tilt</th>
      <th>Down-Tilt</th>
      <th>Forward-Smash</th>
      <th>Up-Smash</th>
      <th>Down-Smash</th>
      <th>Neutral-Air</th>
      <th>Forward-Air</th>
      <th>Back-Air</th>
      <th>Up-Air</th>
      <th>Down-Air</th> 
   </tr>
   <tr>
      <td class = "Neutral">2.2% (punch)<br>1.7% (punch)<br> 4% (kick)</td>
      <td class = "Forward-Tilt">7%</td>
      <td class = "Up-Tilt">5.5%</td>
      <td class = "Down-Tilt">5% (foot) <br> 7% (body)</td>
      <td class = "Forward-Smash">17.8% (fire)<br> 14.7% (arm)</td>
      <td class = "Up-Smash">14%</td>
      <td class = "Down-Smash">10% (front)<br> 12% (back)</td>
      <td class = "Neutral-Air">8% (clean)<br> 5% (late)</td>
      <td class = "Forward-Air">12% (early)<br> 14% (clean)<br> 10%(late)</td>
      <td class = "Back-Air">10.5% (clean)<br> 7% (late)</td>
      <td class = "Up-Air">7%</td>
      <td class = "Down-Air">1.4% (1-5 hits) <br>
         5.5% (hit  6) <br>
         2% (landing)
      </td>
   </tr>
</table>

I'm struggling to get them centered properly. Does anyone have a solution?

https://jsfiddle.net/yt09175x/3/

Answer №1

Your left margins are set to specific numbers, causing your tables to begin at those points and making the data skew the size of the table.

There are several ways to resolve this issue, but here is my suggestion:

table.center {
    margin-left:auto; 
    margin-right:auto;
}
<table class="center">
  <tr>
    <td>First</td>
    <td>Second</td>
    <td>Third</td>
    <td>Fourth</td>
   </tr>
 </table>
 <table class="center">
   <tr>
    <td>One</td>
    <td>Two</td>
    <td>Three</td>
    <td>Four</td>
    <td>Five</td>
    <td>Six</td>
    <td>Seven</td>
   </tr>
 </table>
 <table class="center">
   <tr>
    <td>AAAA</td>
    <td>BBBB</td>
   </tr>
 </table>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to exclude blank fields when displaying a form for printing?

I have a form created using PHP. Although it displays correctly, I would like it to check each field and exclude any div/element/field that is left empty when I choose to print the form. Below is an example of the form code in the printable PHP file. If n ...

Designing Interactive Interfaces using React Components for Dynamic Forms

Is there a way to implement dynamic forms using React Components? For instance, I have a form displayed in the image below: How do I structure this as a React component? How can I incorporate interactivity into this component? For example, when the "+ A ...

The search filter in AngularJS's ng-repeat only activates after the second character is typed

My Angularjs search filter is currently only functioning when the second character is entered into the input box. <input type="text" ng-model="search" class="search-input" id="search-input"><div ng-repeat="x in publishList | filter:search">& ...

Enhance Chart JS by adding scroll functionality for handling large amounts of data

I'm encountering an issue with chart js. When displaying thousands of entries in a single chart, the density makes it difficult to read. I am looking for a way to implement a scrollbar when the data surpasses a certain threshold (or when there is a sp ...

How can I switch between different images using jQuery?

HTML <div class="image_rollover"> <img id="image_one" src=image_one.png"> <img id="image_two" src="image_two.png"> <img id="image_three" src="image_three.png"> <img id="image_four" src="image_four.png"> ...

The control buttons for the HTML video element are hidden

When I create a video element and set controls to true, the controls are not showing even on hover. if (!this._player) { this._player = document.createElement('video'); } this._player.controls = true; this._player.src = xxxxx; I have also s ...

ngif directive does not function properly when subscribe is utilized in ngOnInit

this is the unique component code import { Component, OnInit } from '@angular/core'; import { Subscription } from 'rxjs'; //import { Item } from '../item/item.model'; import { CartItem } from './cart-item.model'; imp ...

The button's unclickability is due to the zIndex being set to -1

How can I create a clickable button? https://i.sstatic.net/BXOjz.png Feel free to check out the sandbox example here: https://codesandbox.io/s/m5w3y76mvy ...

Modifying the selected color of DropDownMenu List items

Hey there! I'm currently trying to modify the color of a material-ui element that is selected, but I'm having trouble finding any resources on how to accomplish this. My goal is to switch this pinkish shade to a more soothing blue hue. https://i ...

Trouble aligning two columns in a row with Bootstrap 4

Hey there! I've encountered an issue with my login form using bootstrap 4. I have set up two col-md-6 columns in a row for "Remember Me" and "Forgot Password", but on mobile devices, the "Forgot Password" section jumps down from the row. Can anyone sh ...

What are the steps to implement string interpolation within a template element in Vue.js?

Currently, I am looping through a dictionary that is imported from a .json file and I want to compare an attribute in my props with a value in the dictionary. The first div defines the attribute variable to be one of the values in the dictionary, specifica ...

Issues with React - Material UI Menu functionality

I'm encountering an issue with the menu/menu item component from material ui when trying to render it based on a condition. Here is my code snippet... const AddSelectItemButton = () => { return ( <> <Fab ar ...

Having trouble importing a component conditionally within a nested component

I am attempting to dynamically import and render one of two components based on the value returned by a prop (lang). If props.lang is set to spanish, then it should import and render a component named <Spain />; otherwise, <UnitedStates />: /* ...

What happens when you implement redirects in `next.config.js` and also use `@next/bundle-analyzer`?

In the configuration file next.config.js, I've included the following code: module.exports = withBundleAnalyzer({ pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'], experimental ...

Applying a CSS hover effect to alter the color of image pixels

Is there a CSS filter that can transform all pixels of an image into a different color? I came across one, but it's not quite what I'm looking for: How to change the color of an image on hover I found a tutorial that transitions from grayscale ...

Create automatic transcripts for videos, including subtitles and captions

Are there any tools or plugins available that can automatically create a transcript of a video for website playback? For example, generating captions and subtitles in the English language. ...

Discord.js encountered an error: Invalid Form Body embed.fields[0].value: Please make sure to fill in this required field

My attempts to create an order command for my discord.js bot have been unsuccessful. Whenever someone uses the command, it doesn't respond and instead presents the following error in the console: "This error originated either by throwing inside of an ...

The script has been modified to add "=s1400" to the image source path, causing the image to fail to load

I have a good understanding of HTML and CSS, but I'm struggling with JavaScript. I noticed that there is a script adding "=s1400" to the image path which is causing the image not to load. You can see the URL is (source files can be viewed using Chrom ...

Jquery split flap animation for text

Do you know of a Jquery plugin that can create the same text animation as shown in this demo: this video? I'm looking for a text animation effect similar to the one made in Flash (you can see it here), but I want to achieve the same result using only ...

How can you turn consecutive if statements into asynchronous functions in JavaScript?

In my code, I have a loop with a series of if statements structured like this: for( var i = 0; i < results_list.length; i++){ find = await results_list[i]; //result 1 if (find.Process == "one") { await stored_proc(38, find.Num, find ...