The inner table provides a slight padding of 1-2 pixels on its left side

Consider a scenario where there is a table:

 <table>
      <tr>
         <td>
            Hello How are you this is a TEST!
         </td>
      <tr>
      <tr>
          <td>
              <table>
                  <tr>
                     <td>
                         Hello this a test 2!
                     </td>
                  </tr>
              </table>
          <td>
      <tr>
 </table>

In this illustration, there is only one TD in the main table, yet three TDs are needed in the child table. Following the above structure results in output like this:

 Hello How are you this is a TEST!
  Hello this is Test 2!

However, the inner table introduces a padding-left of approximately 1-2 pixels. Is there a method to align both statements perfectly?

Answer №1

Make sure to collapse your borders and eliminate cell padding. Additionally, double check that all td and tr tags are properly closed.

https://developer.mozilla.org/en-US/docs/Web/CSS/border-collapse

table {
  border-collapse: collapse;
}

table td {
 padding: 0;
}
 
<table>
      <tr>
         <td>
            Hello How are you this is a TEST!
         </td>
      </tr>
      <tr>
          <td>
              <table>
                  <tr>
                     <td>
                         Hello this a test 2!
                     </td>
                  </tr>
              </table>
          </td>
      </tr>
 </table>

Answer №2

Of course! The extra space you're seeing is caused by a couple of things:

  1. Table cells naturally have some space between them. To remove this gap and make the cells sit flush together, you can use border-collapse: collapse on the parent table element.

  2. Additionally, table cells come with a default 1px of padding. You can eliminate this padding by setting td { padding: 0; }

table {
    border-collapse: collapse;
}

table td {
    padding: 0;
}
<table>
    <tr>
        <td>
            Hello! How are you? This is just a test.
        </td>
    </tr>
    <tr>
        <td>
            <table>
                <tr>
                    <td>
                        Another example for testing purposes!
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

If you want to see a visual demonstration, feel free to check out this JSFiddle.

Answer №3

Give this a shot:

<style>
  table {
    border-spacing:0;

    }
  td {
    margin-left:0px;
    padding-left: 0px;
  }  
</style>

...

<table>
    <tbody>
        <tr>
            <td>
            Howdy! How's it going? Just testing some stuff here!
            </td>
        </tr>
        <tr>
            <td>
                <table>
                    <tbody>
                        <tr>
                            <td>
                            Test test one two!
                           </td>
                        </tr>
                    </tbody>
                </table>
            </td>
       </tr>
   </tbody>
</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

Expanding min-content CSS Grid cell based on neighboring cells

I am working with a CSS grid that consists of two columns and five rows, but the layout changes when the display is above 768px. The first four rows are set to "min-content", while the last row is set to auto. I have defined template grid areas for each ce ...

How can Chinese characters be transformed into XML/HTML-style numerical entities and converted into Unicode UTF-8 encoding?

I have a situation where I need to change a text that contains both English words and Chinese characters into a format that includes XML/HTML-style numerical entities for the Chinese characters. Here's an example of the original text: Title: 目录. ...

Ways to emphasize the current tab on the site's navigation bar?

Here's my question: I have a menu with different items, and I want to make sure that the active tab is highlighted when users switch to another page. I noticed that Stack Overflow uses the following CSS: .nav { float: left; font-size: 1 ...

Authenticating the Gmail API using a specified user ID

Is there a way to manually input email and password for authentication in the Gmail API without using the default Google popup? I need users to enter their login credentials directly, but I can't figure out how to do it. The code I am currently using ...

Utilizing the `theme` property in makeStyles with Material-UI

I am currently working on passing down an muiTheme to a component through the use of ThemeProvider, and I also want to apply it to the children components. Furthermore, I aim to utilize the theme's properties in both components by creating a classes o ...

It is not possible for me to modify the attributes in responsive mode without first generating a new class within the tag

In order to make the attribute work in a responsive manner, I believe I need to create a class within the h2 tag. However, I am unsure where the issue lies. Could it possibly be related to the browser? Check out the image below for reference: this is my p ...

After logging in, I am unable to redirect to another PHP page as the login form simply reloads on the same page

Lately, I've encountered an issue that has persisted for a few days. The login validation is functioning flawlessly. However, the problem arises when attempting to redirect to another page, specifically 'index.php', after logging in. Instead ...

Transforming ASCII Source Files into JPEG Images

I specialize in publishing technical books, available in print, PDF, and Kindle/MOBI formats, with EPUB coming soon. One challenge I have encountered is that the Kindle does not support monospace fonts, which are important for source code listings. The wo ...

"Looping through a list but skipping over a certain element in

Currently, I am utilizing AngularJS to display multiple elements in my HTML code. While Angular is successfully repeating the divs as intended, there seems to be an issue when trying to repeat a specific div. More details provided below: <tr ng-repeat= ...

Trouble with HTML5 Geolocation Functionality

I am having an issue with my Geolocation code. It works fine when I run it on my desktop, but when I upload it to a free hosting service like [http://darkdays.byethost14.com/cc.html], the button does not work and nothing pops up. Can anyone help me trouble ...

jquery's each method is not functioning as intended and causing unexpected issues

I'm in the midst of developing a website, and one section requires users to input their details into a form. My goal is as follows: When a user clicks the submit button with any empty fields, I want a span element (initially set to display none in CS ...

Can you show me the procedure for retrieving a particular element with selenium? (Page Source provided)

Disclaimer: I must admit that my knowledge of HTML and CSS is minimal, so please bear with me! Hello everyone, I am attempting to utilize selenium[Java] to browse a website and retrieve a file. While I managed to successfully get past the login page, I fi ...

CSS - turn off inheritance for font styling

I am trying to figure out how to turn off the font:inherit property in Ionic's global CSS. This property is causing issues when I try to style text using ng-bind-html, as it adds unnecessary classes to elements like i and bold. I attempted to override ...

Automate tasks without the need for a traditional form, simply using a text box and a

I've exhausted my search efforts on Google, looking for answers to any question relating to my issue. The webpage I am attempting to submit resembles this setup: there is no form present and the objects are not organized within a form structure. While ...

Is there a way to switch my image buttons to a different image when clicked?

In order to create interactive buttons for a website, I designed four unique .PNG images using Photoshop. Two of these images are intended to serve as default buttons, while the other two are meant to be used as "post-click" buttons. For the default butto ...

Align the text characters vertically within a word or sentence

I currently have a logo that consists of lines and text. I would like to create a similar version using CSS for my website. https://i.sstatic.net/vxS8Z.png My goal is to have the letters "T - S o N" appear in one line with the letter "o" positioned verti ...

Designing a submenu with HTML and CSS

As a novice in web development, I recently attempted to create a website featuring a horizontal main menu with a vertical submenu. However, I encountered an issue when hovering over a list item in the main menu - the submenu would drop down and disrupt th ...

Setting up a PHP email form for offline use

Here is the code I am currently working on: <?php if(isset($_POST['submit'])){ $to = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086d65696164486d70696578646d266b6765">[email protected]</a>"; // ...

When a table row is selected, set the OnClick attribute of an input to the value of the TD cell in that row based on

I'm really struggling with this. So, here's the issue - I have a table where rows get assigned a class (selected) when clicked on. Now, there's an input inside a form that needs to redirect to another page when clicked, and it also needs t ...

When using the `justify-content: flex-end` property, the `overflow: auto

I'm attempting to align elements to the right within a container and hide any overflowed elements while still allowing them to be accessed via a scrollbar. However, I've noticed that the scrollbar disappears when using justify-content: flex-end. ...