What could be causing my HTML table to resize images from left to right?

My latest attempt at creating a simple HTML table involved filling it with placeholder images and spacing them out using a background color. However, the end result was not what I expected:

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

Upon closer examination, you'll notice that the rightmost image appears smaller than the others - quite odd indeed.

td {
  padding: 5px;
  background-color: #C6C6C6;
}
<table>
  <tr>
    <td>
      <img src="http://www.examplesite.com/pholder.png" />
    </td>
    <td style="background-color: #FFFFFF;"></td>
    <td>
      <img src="http://www.examplesite.com/pholder.png" />
    </td>
    <td style="background-color: #FFFFFF;"></td>
    <td>
      <img src="http://www.examplesite.com/pholder.png" />
    </td>
    <td style="background-color: #FFFFFF;"></td>
    <td>
      <img src="http://www.examplesite.com/pholder.png" />
    </td>
    <td style="background-color: #FFFFFF;"></td>
    <td>
      <img src="http://www.examplesite.com/pholder.png" />
    </td>
  </tr>
</table>

I suspect that the issue may be related to how I spaced the table with margins and empty columns. Any suggestions on how to fix this without compromising the neat visual design?

Note: The website is mobile-responsive and automatically scales images, so setting fixed dimensions will not be effective for me.

Answer №1

While I don't have a direct answer to your question, I can advise against using tables for layout as it is considered poor practice, especially if you aim for responsiveness in your site design. Tables are best suited for displaying tabular data.

Instead, utilizing divs and CSS with media queries will ensure a consistent layout. It may require more effort, but there are plenty of resources available to guide you through the process.

====EDIT ====

To address the current issue, consider adding a specific width to the td elements. This will maintain their size when displaying a known number of elements, such as the 5 present in your table:

<tr>
    <td width="20%">image</td>
    <td width="20%">image</td>
    <td width="20%">image</td>
    <td width="20%">image</td>
    <td width="20%">image</td>
</tr>

Tables automatically adjust spacing based on content which can cause issues with cell proportions.

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

"How can I adjust the height of a Bootstrap column to match the height of its neighboring column

In my Bootstrap 4 layout, I have set up two columns... The left column contains three cards in columns The right column has a list group The content in the list group is longer than that of the cards on the left side. Is there a way to make the height ...

Currently, I am compiling a list of tasks that need to be completed, but I am encountering a dilemma that is proving difficult to resolve

Recently delved into the world of Javascript and encountered a roadblock that I can't seem to overcome. Here's the snippet of code causing me trouble: add = document.getElementById("add"); add.addEventListener("click", () => { console.log("Ple ...

Unable to place within div

Utilizing HTML5 to implement the "DnD" function. There is a button that adds divs. I want to be able to drag items into these newly added divs. Currently, I can only drag into existing divs and not the ones added later. How can I resolve this issue ...

The outcome of the Python web crawling did not meet our expectations

After using Selenium to scrape web data, I encountered an issue where it only displayed 96 out of 346 products instead of the expected 346. Does anyone have suggestions on how to fix this problem? The crawling code is placed right after the loop for clicki ...

Using ReactJS to dynamically change styles based on state variables can sometimes cause CSS

Currently delving into the world of React. Learning about states/props and the art of dynamically altering elements. I've set up the component states like this: constructor(props) { super(props); this.modifyStyle = this.modifyStyle.bind(thi ...

An issue arose when attempting to load the page using jQuery

Currently, I am implementing the slidedeck jquery plugin on my webpage to display slides. While everything is functioning properly, I am facing an issue with the CSS loading process. After these slides, I have an import statement for another page that retr ...

Using Reactjs: How do you insert HTML code into the primaryText of a list item?

Is it possible to include a span element inside a ListItem like so: <ListItem primaryText={"<span class='inner'>Some important info</span>" + item.title} /> When I view the rendered content, the output is not an HTML span ...

What is the best way to determine when an IndexedDB instance has finished closing?

In the world of IndexedDB, the close method operates asynchronously. This means that while close finishes quickly and returns immediately, the actual connection closure happens in a separate thread. So, how can one effectively wait until the close operatio ...

TinyMCE toolbar missing the "hr" option

I am encountering an issue while using TinyMCE as my editor. I have added the plugin as instructed, but I cannot find the "hr" button/option in the editor interface. If anyone has any insights or solutions to this problem, please share! This is how I am ...

Add a JSON file containing an image path as a value into a CSS background property

I currently have a MongoDB database containing documents with 'img' values structured as follows: "img": "../folder/img.jpg" Would it be feasible to utilize this string in my CSS for modifying the background image? This is essential because I n ...

What steps should I follow to track an event using Firebug?

When I examine the element, how can I discover all of the events that are attached to it? ...

Guide to importing a scss file into a scss class

Is there a way to apply a different theme by adding the "dark-theme" class to the body? I've attempted the following implementation: @import '../../../../node_modules/angular-grids/styles/material.scss'; .app-dark { @import '../../. ...

Add the value of JQuery to an input field rather than a select option

Is there a way to append a value to an input field using JQuery, instead of appending it to a select option? Select option: <select name="c_email" class="form-control" ></select> JQuery value append: $('select[name=&q ...

When a div slides down on page load, the div will slide up when a button is clicked

I am trying to make a div slideDown on page load. The goal is to have the div automatically slideDown after 2 seconds, which contains a responsive image and a button named "z-indexed". However, I am having trouble getting the same div to slideUp when the z ...

Develop diverse canvases with shapes such as ovals, rectangles, and circles

My task involves creating a canvas in an oval shape. Below is the code I am using in jQuery with the created object of canvas. $("#decalshap").change(function() { alert("decal"); var shap = $(this).val(); if(shap=="oval") ...

Submitting data through a PHP server-side script

I am facing a dilemma regarding why the form is not submitting and directing me to the index.php page. Being new to PHP, I am attempting to utilize the User object. Below is my current progress: <main> <header> <h1>Cr ...

Challenge encountered with AJAX request

Whenever I trigger an AJAX request to a JSP using a dropdown menu, it works perfectly fine. However, when I try to trigger the same request using a submit button, the content vanishes and the page refreshes. function najax() { $.ajax({ url:"te ...

Another drop-down is hiding the bootstrap-select drop-down from view

What could be causing some parts of the first drop-down menu to be hidden by another drop-down menu below in the code snippet provided? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv= ...

Display the output returned from the AJAX request (HTML and/or JavaScript)

How can I effectively render content from an ajax call when the response may include html and/or javascript? I used to rely on document.write() for synchronous calls, but now that I need to use asynchronous calls, I have to find a different approach to dis ...

Is there a way to customize the appearance of the current slide in slick.js with jQuery?

I am looking to customize the appearance of the currently active slide by giving it an orange border. Keep in mind that the class for the active slide is : slick-active and the structure is as follows : <div class='slick-slide slick-active' ...