Is there a way to stop a nested table from causing the parent table to expand?

This is where I'm demonstrating the issue: https://jsfiddle.net/ahnfcwdo/1/

Below is the structure of the table:

table { 
    max-width:100%;
    overflow: auto;
}

.table1 {
    border: 1px solid red;
}

.table2 {
    border: 1px solid blue;
    overflow-x:scroll;
    display:block;
}
<table class="table1">
  <tr>
    <td>column a</td>
    <td>column b</td>
    <td>column c</td>

  </tr>
  <tr>
    <td colspan="3">
      <table class="table2">
        <tr>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>

      </table>
    </td>
    </tr>
</table>

For each detail row, the parent table will contain a nested table. The nested table may have more columns than can fit on the screen. I prefer the nested table to have a horizontal scroll bar rather than expanding the parent table horizontally to fit the overflow.

In the demo, I'm showing that I don't want the blue border of the nested table to push the red border off the screen. I want the scrollbar to appear for the blue bordered table within the confines of the red border table.

Answer №1

Add the following code to the parent table: table-layout:fixed; width:100%;

table {
  max-width: 100%;
  overflow: auto;
}
.table1 {
  border: 1px solid red;
  table-layout: fixed;
  width: 100%;
}
.table2 {
  border: 1px solid blue;
  overflow-x: scroll;
  display: block;
}
<table class="table1">
  <tr>
    <td>column a</td>
    <td>column b</td>
    <td>column c</td>

  </tr>
  <tr>
    <td colspan="3">
      <table class="table2">
        <tr>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>
          <td>column</td>

      </table>
    </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 uncheck a checkbox from a list, even if some of them are already unchecked?

I am attempting to implement a feature where checking a checkbox selects all others in the list, and unchecking one deselects all. Currently, only selecting one checkbox allows me to check all the rest, but unchecking one doesn't trigger the reverse a ...

Enclosing two smaller boxes within a larger box

I'm attempting to replicate the layout shown in the desired.png file (specifically with an outer box surrounding two inner boxes). Currently, my code doesn't display the expected outer box around the two inner boxes. How can I modify it to achie ...

What is the best way to define the relative path and folder paths in HTML and CSS when working in Visual Studio 2012?

Working on a basic HTML project that includes css and javascript. Within the project folders named css, scripts, and images are used for organization. The project structure can be seen in the provided image. https://i.sstatic.net/OwCSL.jpg The issue that ...

Problematic situation concerning the lack of effectiveness of jQuery's .removeClass() function

I am encountering a strange issue with some code that adds and removes classes from an element in JavaScript. Despite my best efforts, I cannot replicate the odd behavior in a simple jsfiddle example. Below is the relevant section of JavaScript that is ca ...

The ng-controller (dropdown menu) is functioning properly when tested locally and on JSFiddle, however, it is not working on

My HTML website with ng-app is functioning properly when tested locally and on certain coding platforms like JSFiddle and CodePen. However, it seems to encounter issues when deployed on Google Sites, Github, W3, and similar websites. The main functionalit ...

Should I use several if get statements on one page, or spread them out across multiple pages in PHP structure?

After working with PHP for a few years, one of my ongoing dilemmas is how to best structure my pages. Should I follow the current approach: if(getValue('action') == "jobsFilter" && getValue('jobType') == "open") ...

The HTML5 Canvas Misalignment Issue

I currently have some HTML code that includes a canvas, span, and a button: <canvas id='myCanvas'></canvas> <span id='coords'></span> <button class='clear'>clear</button> Accompanying this ...

Sending emails to multiple recipients with different content using Nodemailer

I have been working on a method to send emails to multiple recipients while also passing the user attribute, which contains the name of the recipient, to the html template. (I AM UTILIZING NODEMAILER as a nodejs module) My current code looks like this: S ...

What might be causing Chrome to not wrap a centered column to the next line in Bootstrap 4 beta?

Utilizing bootstrap 4 beta, my goal is to center a line of text inside a column and ensure that if the text exceeds the line width, it wraps to the next line. I attempted to achieve this by using justify-content-center on the row in combination with col-a ...

Display a division upon clicking a button using AngularJS and HTML

Looking to implement a functionality in my HTML page using angularJS. I am currently learning angularJs and experimenting with a feature where clicking on a button will display a specific div (EmployeeInfoDiv) on the webpage. The idea is to fill out some t ...

Tips for utilizing the output of a pre-defined function within another function in SASS

How can I effectively utilize the outcome of darken( $var, 10% ) in the SASS function oppositeColor( $darkenedColor )? The code I am working with currently looks like this: $color1: #000000 !default; $color2: darken( $color1, 5% ) !default; $color3: oppos ...

Overflow-x in HTML5 Websites

I recently launched my website in the "alpha" stage - I have implemented full mobile support using media queries. It displays perfectly when the browser window is resized, but I noticed a strange space to the right of everything on my Samsung Galaxy Note ...

Using a SASS watcher to keep an eye on every folder and compile them into a single CSS

I'm interested in setting up a folder structure like this: assets - scss - folder file.scss anotherfile.scss anotherfile.scss anotherfile.scss - anotherfolder file.scss anotherfile.scss anotherfile.scss ...

Exploring XPath: strategies for excluding text within nested elements

if I come across some HTML structure like this: <div class=unique_id> <h1 class="parseasinTitle"> <span> Game Title </span> </h1> Game Developer </div> Is there a unique way to extract only the "Game Develo ...

Notifying Users of JavaFX Applet Web Page Refresh and Closure

Is there a way to detect when a user closes or refreshes a web page with a JavaFX applet embedded in it? I need to perform some clean-up tasks in my code when these events occur. In the past, Java Applet had callback methods for this purpose. How can I ac ...

Leveraging AngularJS to enhance the dynamic HTML content within Datatables

My angular application includes a Datatable where I alter cell content to include HTML elements. In the given code snippet, I specifically modify the cell content of the 5th column to incorporate links. Additionally, I intend to implement a tooltip featur ...

Circular arrangement using D3 Circle Pack Layout in a horizontal orientation

I'm currently experimenting with creating a wordcloud using the D3 pack layout in a horizontal format. Instead of restricting the width, I am limiting the height for my layout. The pack layout automatically arranges the circles with the largest one ...

If there is data in MySQL, proceed to display the results on the page; if not, display a check

I am struggling to implement a small logic that I can't seem to figure out here. My goal is to retrieve MySQL data from the database and echo it on a .php file. Before doing so, I need to check if the data is available. If it is, then I want to proce ...

Update the value of a JavaScript variable in an HTML template by targeting the element with a specific

Within my testFile.html HTML file, the following code is present: <div id="image-type-placeholder">marinaa</div> In my JavaScript file: const CourseImageUpload = BaseComponent.extend({ /** * @property {function} */ templat ...

The program is designed to only allow up to two images to be wrapped

I'm struggling with a short jQuery program that I need help with. The problem is, I can't seem to get it to wrap more than two images in the same row. My goal is to create a website that side-scrolls, and I thought this approach would be the simp ...