Why does this inner HTML table always adjust its width based on the content within it? Is there a way to make it match the width of its container instead

I'm not very familiar with HTML and CSS, and I've come across a problem. Here is the CSS structure in question:

<!-- TECHNICAL REFERENCE: -->
<div id="referenteTecnicoTab">
  <table width="800px" class="standard-table-cls table-header-cls">
    <thead class="opening">
      <tr>
        <th>
          <img class="imgAccordion" src="img/arrow.gif"/>
          Invoice Search
        </th>
      </tr>
    </thead>

    <tbody class="expanded" style="display: none;">
      <tr>
        <td>
          <div id="ricercaFattureContent" class="accordion-pane-content">

            <table width="100%" class="standard-table-cls table-header-cls" >
              <thead>
                <tr>
                  <th style="text-align: center; border-left: 0">Invoice Search</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td width="100%">
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
</div>

</div>

Within the id=ricercaFattureContent div, there's a table with a thead displaying the text "Invoice Search" and a tbody showing the example text "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."

The issue is that the table's width matches the content inside it (in this case, the "aaa....aaa" text).

How can I make the table have the same width as its container?

I've been struggling to figure it out, and through FireBug, it appears that the tr within the tbody takes on the width determined by its content. This portion of the code explains it:

<table class="standard-table-cls table-header-cls" width="100%">
  <thead class="opening active">
  <tbody class="expanded" style="display: block;">
    <tr>
      THE tr TAKE THE WIDTH OF ITS CONTENT

As a result, I end up with something like this:

I want the table to match the width of its container. Any suggestions?

Thanks

Answer №1

It appears that there is a width="800px" attribute on the table element, and the tbody is set to display: none;

You can view the corrections in this fiddle: http://jsfiddle.net/ak0ygz2n/

I highlighted the container in orange to demonstrate the concept, and adjusted the table width to be 100% of the container.

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

Tips for preventing a React component from scrolling beyond the top of the page

I am looking to achieve a specific behavior with one of my react components when a user scrolls down a page. I want the component to reach the top of the page and stay there without moving any further up. Here is an Imgur link to the 'intranet' ...

Download a complete website using PHP or HTML and save it for offline access

Is there a way to create a website with a textbox and save button, where entering a link saves the entire website like the 'save page' feature in Google Chrome? Can this be done using PHP or HTML? And is it possible to zip the site before downloa ...

I am having trouble showing the background image in the div

I created a 960 layout using 3 divs to easily organize child divs with images and text. However, I'm having trouble getting the background image of the first div to display. Can you help me figure out what I'm doing wrong? This is the concept f ...

Tips for aligning buttons vertically within the form-row class in Bootstrap 4

I'm facing an issue where I cannot get a set of buttons in line with labels when using different column widths in Bootstrap. The behavior of a button assigned to a specific column width, like col-3, is not the same as a button assigned with automatic ...

Looking to include some extra padding when an item is displayed - jQuery

So, I'm working on a jQuery code snippet that controls the visibility of a rectangle element: $("#rectangle").hide(); $("#toggle-rec").click(function () { $("#rectangle").toggle(2000); }); This code hides the rectangle initially and toggles it ...

The project is experiencing difficulties in loading the Module CSS

Currently, I am working on a React module and have set up a React project to demonstrate the functionality of this module. Initially, everything was working smoothly until I encountered an issue with the webpack configuration related to the CSS loader. { ...

alteration of colors in a Chartist chart

Currently, I am working with a chartist graph where the colors are defined at a framework level. However, I need to make changes to the colors for a specific graph without altering the framework level settings. I attempted to create a .less file, but unfor ...

How can I align two div buttons at the top and bottom to appear on the left and right sides?

How can I change the position of two buttons from top and bottom to left and right as shown in the second image? I am utilizing Floating Vue, so the buttons will be contained within a div. Is it feasible to adjust their position accordingly? Check out th ...

Discovering a class within a div element using Selenium

Currently, I am attempting to utilize Selenium in Python to locate and click on the 'X' button. This action will redirect me to the next page where I can extract some crucial information. However, I am encountering difficulties in finding the ele ...

Autoprefixer encountered a TypeError while executing the npm script: Patterns must be specified as a string or an array of strings

Upon executing npm run prefix:css, the following error message is displayed: Error: Patterns must be a string or an array of strings { "name": "natours", "version": "1.0.0", "description": "A project for natours", "main": "index.js", "script ...

CSS hover effect applied uniformly to all link children

Here is the HTML code snippet I am working with: <a href="">Bioshock 2<span> - Xbox 360 review</span></a> My goal is to style the first part of the link differently from the span. The desired styling should look like this: https: ...

Swap out original source files in HTML with minified versions

I have successfully utilized a maven plugin to create a minified and compressed version of my CSS and JavaScript files. Now, I am looking to update the section in my main HTML page that currently loads all those individual files. Here is what it looks lik ...

Unable to attach an onClick event handler to <TableRowColumn> element using Material-UI in React

In the past, I had a feature that allowed me to change the color of the text from red to green by clicking on a table cell. After introducing Material-UI in my React app and replacing the <td> tags with <TableRowColumn> tags, I noticed that th ...

Basic alignment in a table and on a webpage using HTML

I have a basic HTML table that needs some alignment adjustments. <table align="center" border="1" cellpadding="0" cellspacing="0" style="width:1000px"> <thead> <tr> <th scope="row">BB<br /> ...

Utilizing Node.js modules in a frontend HTML file with the help of browserify

I am encountering difficulty using a node.js module on my website with browserify. The example provided only demonstrates how to run a separate JavaScript file, not how to incorporate the node.js module within the .html file itself. This seemingly simple i ...

Trouble with "data-bs-dismiss" functionality in Bootstrap 5

I am faced with an issue involving two modals. My goal is to have the "Novo Avatar" button close the modal with the ID #modal_debug and then open the modal #modal_newAvatar. However, instead of closing the current modal, it simply opens the new one on top. ...

Is there a way to retrieve a CSS file using AJAX from a separate origin?

Whenever I am trying to load a CSS file via AJAX from my dreamhost account, I encounter the error message that says No 'Access-Control-Allow-Origin' header is present on the requested resource. After searching for solutions online, I stumbled upo ...

A div without any content and styled with a percentage height will appear as invisible

I'm working on creating a responsive background image for a room, where I want the wall to take up 2/3 of the vertical height and the carpet area to cover the remaining 1/3. Here are snippets of the code I've been using - my issue is that I am t ...

Learn the methods for successfully transferring dynamic values from Angular to a jQuery script

This is the script that I have included in my HTML code: <div class="progress-bar"></div> <script type="text/javascript"> $('.progress-bar').gradientProgressBar({ value: $(this).attr('$scope.moodvalue'), ...

Ways to establish the gradient

Here is the code snippet I am currently working with. .imgcol1 { background-image: url(https://picsum.photos/200/300); background-repeat: no-repeat; background-size: cover; height: 190px; width: 520px; } .col1 { margin: 75px; } .grad { b ...