Ways to arrange and space out td values

Here is an example of my HTML table:

<table>
  <tr>
    <td>123 - 20 - 20</td>
  </tr>
</table>

The numerical values in the table are retrieved from a database and displayed like in this image: https://i.sstatic.net/OWtvS.jpg

How can I ensure that all values (numbers) are properly aligned in the table? Thanks

Answer №1

For optimal formatting, it is recommended to separate each "substring" (number and operator) into its own table cell and apply text-align: center to all cells. This will ensure that everything remains centered, regardless of the length of the number.

td {
  text-align: center;
}
<table>
  <tr>
    <td>27.082</td>
    <td> - </td>
    <td>5</td>
    <td> - </td>
    <td>5</td>
  </tr>
  <tr>
    <td>3.905</td>
    <td> - </td>
    <td>2</td>
    <td> - </td>
    <td>2</td>
  </tr>
  <tr>
    <td>13.602</td>
    <td> - </td>
    <td>2</td>
    <td> - </td>
    <td>3</td>
  </tr>
  <tr>
    <td>0</td>
    <td> - </td>
    <td>0</td>
    <td> - </td>
    <td>1</td>
  </tr>
  <tr>
    <td>43715</td>
    <td> - </td>
    <td>513</td>
    <td> - </td>
    <td>312</td>
  </tr>
</table>

Even with significant digit counts, proper alignment is maintained:

td {
  text-align: center;
}
<table>
  <tr>
    <td>27.082</td>
    <td> - </td>
    <td>5</td>
    <td> - </td>
    <td>5</td>
  </tr>
  <tr>
    <td>3.905</td>
    <td> - </td>
    <td>2</td>
    <td> - </td>
    <td>2</td>
  </tr>
  <tr>
    <td>13.602</td>
    <td> - </td>
    <td>2</td>
    <td> - </td>
    <td>3</td>
  </tr>
  <tr>
    <td>0</td>
    <td> - </td>
    <td>0</td>
    <td> - </td>
    <td>1</td>
  </tr>
  <tr>
    <td>43750311251242145</td>
    <td> - </td>
    <td>5313451413</td>
    <td> - </td>
    <td>31434132</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

Is it possible to run a Universal Windows Platform desktop app on an Android mobile device?

After successfully developing a Universal Windows Platform app in Visual Studio using WinJS, JavaScript, CSS and HTML, I am now interested in leveraging the same code base to create an Android application. Could you guide me on the necessary steps to run ...

What is the need for assigning a name to every object in the Firebase data structure?

Exploring a simple array example from Google "chats": { "one": { "title": "Historical Tech Pioneers", "lastMessage": "ghopper: Relay malfunction found. Cause: moth.", "timestamp": 1459361875666 }, "two": { ... }, "three" ...

What is the best way to center this menu on the web page?

Is there a way to center this menu on the web page for better alignment? Any suggestions on improving the code are welcome. Thank you in advance. Edit: Also, how can I modify the hover effect to change the background color to green and make it expand full ...

Showcase each video stored within a specific directory in the form of a list using HTML 5

I'm working on an application that requires me to showcase a series of videos on a single HTML5 page using the video tag. Despite successfully uploading files to my folder, I am struggling to display them properly. My search for a solution has been fr ...

Attempting to arrange six images in a row using dividers

Having trouble aligning six images (2 per row with text in between) to the center of your webpage? Don't worry, we've got you covered! Check out the screenshot attached for reference and let us know how we can assist. Click here for a snapshot of ...

Switching between fixed and unfixed divs causes two absolute divs to alternate

I am currently working on a code to keep a fixed div ("two") in place between two absolute positioned divs ("one" and "footer") while scrolling. However, there is an issue that arises when the browser window is resized. The distance between the footer and ...

Troubleshooting the issue of autoplay not functioning in HTML5 audio

I'm facing a strange issue with my code - the autoplay feature for audio is not working as expected. Typically, whenever I insert this particular piece of code into a website, the music starts playing automatically. However, it seems to be malfunctio ...

Tips for accessing a URL with a specific value in the HTML file

This form submits a URL in this format: <form action="search.php?search=" method="GET" id="search-form"> <input id="search-text" name="search" type="text" maxlength="30" placeholder="type keyword"/> <button type="submit" name ...

The Safari 7.1+ browser seems to be having trouble with the spotlight effect

Why is the CodePen not functioning properly in Safari? Despite working well in Chrome and Firefox, it completely fails to work in Safari 7.1+. Can anyone provide some insights? http://codepen.io/cchambers/pen/Dyldj $(document).on("mousemove", function( ...

Show the sticky dropdown only when an error occurs during submission

My goal is to have the dropdown selected only when an error occurs, and here is the script I am using <select name="usertype" id="usertype" class="form-control"> <option value="">Please select the user type</option> <option va ...

When using jQuery, the value of an input type text field remains constant despite any alerts

My issue involves an input text used to check if the corrected values are being displayed in an alert. However, when I modify a value in the form and check if the updated value appears in the alert box, it still shows the old value. Below is the relevant ...

Achieve vertical alignment and responsiveness of elements in primefaces using css techniques

In order to vertically align 2 elements inside an outputpanel, I initially used a margin-top of 3em. However, this method proved to be non-responsive, as shown in the following images: https://i.sstatic.net/yMRXc.png In mobile view: https://i.sstatic.net ...

Retrieve CSS content from a file hosted on the local server

Is it feasible to use a locally hosted CSS file for styling a website managed by a server-based CMS? I am interested in utilizing SASS for local CSS development while retrieving the HTML content from a centrally hosted CMS server. ...

"Can someone guide me on the process of transmitting data to a client using Node in combination with

I am new to web development and struggling to understand how to transfer data from the Node server to the client while also displaying an HTML page. I am aware that res.send() is used to send data, but I'm having difficulty maintaining the client disp ...

What is the best way to add an insert button to every row?

Take a look at the image provided. When I click on any register button, the last row is being inserted instead of the desired row. What I'm aiming for is this: when I click register, the entire selected row should be stored in a separate table. Whe ...

Is there a way to incorporate cell highlighting on IE?

I've implemented a method to highlight selected cells based on the suggestion from jointjs. It surrounds the cell with a 2-pixel red border, which works well in Chrome. However, I need the outline to work in IE as well. Unfortunately, when I reviewed ...

Error: Invalid Month in SQL WHERE Clause Date

I'm attempting to execute this SQL query in SQL Developer using an Oracle Database. My goal is to select all columns where the A.APPT_DATE is at least 2 months old, but I keep encountering a 'not a valid month error', which I have highlighte ...

The background of the ACTK Modal Popup vanishes after multiple instances of scrolling up and down

The issue I'm facing is with the AJAX Control ToolKit Modal Popup's background (the blind curtain) disappearing after scrolling up and down several times. I have attempted to resolve this by applying various CSS styles, but unfortunately, none of ...

What is the best way to incorporate Bootstrap's datepicker into a website?

I'm currently working on an AngularJS application. Here is the code I have: <directive date="date" date-format="YYYY-MM-DD" > <input ng-model="Date" type="text"/> </directive> Is there a way to integrate an Angu ...

Nesting Multiple Click Directives in AngularJS

I am facing a situation where I have two directives in play – one is enclosed within a specific view, while the other is applied to the container of that view. <div id="content" data-panel='{{ pNav }}' close-content> <div class="i ...