What is the method for distributing additional width in a table among its columns?

Have you ever wondered how excess space in an HTML table is distributed among the columns? I too was curious about this, but couldn't find a definitive answer even after extensive searching. Therefore, I decided to create a simple test page to investigate.

<html><head>
    <style type="text/css">
        td, div{
            border: 1px solid black;   
        }
    </style>
</head><body>
    <table width=500>
        <tr>
            <td><div style="width: 200px;">Big td</div></td>
            <td><div style="width: 100px;">Small td</div></td>
        </tr>
    </table>
</body></html>

After running the test (in google chrome), it became apparent that browsers distribute the extra space proportionally among the columns. This means that columns are allocated a percentage of the additional space based on their original size. This discovery led me to wonder:

  1. This post serves as documentation for others who may encounter the same question.
  2. Is this behavior consistent across all browsers? (Try testing it on yours)
  3. Is there a way to modify this allocation using CSS? Specifically, can we make the browser distribute the extra width evenly among the columns?

Answer №1

To adjust the horizontal space allocation, consider implementing flexbox CSS rules. Explore and experiment with the initial number in the "flex" attribute. This value dictates which elements receive additional space and the amount they receive.

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

Discovering visible ID numbers on the screen

My content includes the following: <div id="sContainer"> <div class="message0" id="l0">Initial Content 111</div> <div class="message1" id="l1">Initial Content 222</div> <div class="message2" id="l2">Initial ...

Creating a draggable element in JavaScript using React

I've been attempting to create a draggable div element, but I'm encountering some perplexing behavior. The code I'm using is directly from w3schools and it functions correctly for them, however, in my implementation, the div always shifts to ...

Using JavaScript to generate a <style> element and accessing the cssRules

After spending countless hours trying to solve this problem, I'm hoping that my question isn't too foolish. This is a continuation of a previous question about creating a style tag with JavaScript on Stack Overflow. The solutions provided by Tom ...

Encountering problems due to the addition of an event listener on my webpage

Currently working on a nodejs app utilizing react and encountering an issue when running yarn start. The error message "TypeError: btn_bmi.addEventListener is not a function" keeps popping up. This setup has worked for me before but now I'm unsure abo ...

Would you like to learn how to set an auto-play video as the background in a webpage section, similar to the one found on http://www8.hp.com/in/en/home.html?

I was browsing the HP-India website and noticed they have a cool autoplay video in the background of a section below the header. I would love to recreate something similar on my own website. Any tips on how to achieve this? ...

Importing a .js file into HTML with AJAX

The following JavaScript code is located within index.html between "<script type="text/javascript">" function callanular() { peticion_http = new XMLHttpRequest(); peticion_http.onreadystatechange = showContent; peticion_ht ...

"Div vanishes mysteriously while CSS transition is in progress

When I have two divs positioned alongside each other, and one collapses to the left upon clicking a button, the remaining div on the right fills the available space due to its width being set at 100%. However, during the collapsing transition, the right di ...

Interact with the :before pseudo element when hovering over an element

Is there a way to manipulate the :before pseudo element when hovering over the main element? My goal is for the pseudo element to change its height when I hover over the main element. This is how my code looks: HTML <div class="object">& ...

Struggling to use the innerHTML method to update a div within another div element?

<!DOCTYPE html> <html> <head> <title>Business Information Card</title> <script type="text/javascript"> window.onload = init; function init(){ var button = document.getElementById("populate ...

Different position of navigation list-style visible in Chrome browser

Currently, I am working on a website where the main menu navigation is designed using the list-style property to separate each menu item. In Firefox, everything appears as intended with small circles between each menu item. However, when viewed in Chrome, ...

Tips for transferring information from a form to your email address

I am trying to find a way to automatically send form data to my email without the user having to open their inbox. I attempted to use the "mailto" function but it didn't work as desired, still opening the email box. Here is the script I tried: functio ...

Adjustable dimensions for slider images

My goal is to add a rotating slider to my website, but I'm facing an issue where it needs to occupy the entire screen on both mobile and desktop devices. However, setting the width to 100% makes the image not visible. I am utilizing code from this lib ...

experiencing challenges with jQuery event handlers in version 1.6, but not encountering the same issues in newer releases

Presently, I am using a version 1.6 of the Jquery library, which takes time to update. I am attempting to incorporate a Jquery event handler. I have a collection of divs that contain many buttons. These buttons are constantly being added dynamically, and ...

The content of the HTML request may not always be displayed exactly as it appears in the browser

I've been trying to extract comments from a website using Python and urllib. Although I am successful in obtaining the HTML, I noticed that the comment section is missing. Here's what my Python code retrieves: <div data-bv-product-id="681012 ...

What is the best way to initiate a Bootstrap carousel so that it begins with the first image every time a modal window appears

I am in the process of creating my own portfolio to showcase my work. I have implemented a feature where clicking on an image opens up a Bootstrap carousel. However, I'm facing an issue where the carousel doesn't always start with the first imag ...

React - Obtain User Login Details and Verify

I am working on a React project that includes a Login Form. The code has been organized into small components for reusability, but I am unsure of how to retrieve and validate user credentials (username and password). Is there a method available to validate ...

What is the best way to incorporate several php files into a WordPress post?

I have developed a system that retrieves information from a database and presents it in multiple text files. Now, I am looking to move this system to a page on a WordPress website. I have already created a custom page named page-slug.php and added the ne ...

Tips for showcasing API responses in HTML

Although I have successfully retrieved the data, I am facing issues with efficiently displaying it on an HTML page. Currently, my solution involves using two endpoints - one to fetch API data and another to load the HTML with a script. However, this appro ...

How can I fetch a value from a database and set it as the selected option in a

I am facing an issue with the usage of the selectpicker plugin from Bootstrap in order to select multiple items. My requirement is to create a modal for editing where the data is fetched from previous records, particularly an array. I am looking for a way ...

Eliminating the Skewed Appearance of Text in Input Fields Using CSS

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Customized Page Layout</title> <script src="https://c ...