Set the cell width in relation to the width of the parent table header

Is there a way to adjust the width of inner table cells based on the parent table header? I attempted the following, but how do I set the inner table cell widths according to the parent header cell?

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

Here's what I've tried using Bootstrap:

<div class="table-responsive">
  <table class="table table-sm table-bordered block-table">
    <thead>
      <th>Sr.</th>
      <th>Product</th>
      <th>Unit</th>
      <th style="width: 15%">Serial Number</th>
      <th>Date</th>
      <th>Mac. Address</th>
      <th>Batch No.</th>
      <th>Qty</th>
      <th>Std Pkg</th>
      <th>Start Range</th>
      <!-- <th>Assigned Quantity</th> -->
    </thead>
    <tbody>
      <ng-container *ngFor="let inventory of inventoryList;let i=index">
        <tr style="cursor: pointer;" (click)="toggleProductEntryTable(i)">
          <td>{{i + 1}} </td>
          <td> {{inventory?.displayString}} </td>
          <td>{{inventory?.uomString}} </td>
          <td colspan="7" style="padding: 0px">
            <tbody>
              <tr style="display: table-header-group" *ngFor="let productEntry of inventory.inventories;let proEnt=index">
                <td style="display: table-cell;min-width: 160px"> {{productEntry?.subDetail?.serialNo}} </td>
                <td style="display: table-cell;"> {{productEntry?.inventory?.date}} </td>
                <td style="display: table-cell;"> {{productEntry?.subDetail?.macAddress}} </td>
                <td style="display: table-cell;"> {{productEntry?.subDetail?.batchNo}} </td>
                <td style="display: table-cell;"> {{productEntry?.checkoutDetail?.consumed - productEntry?.checkoutDetail?.assignedCount}} </td>
                <td style="display: table-cell;"> {{productEntry?.subDetail?.standardPackingQuantity}}</td>
                <td style="display: table-cell;"> {{productEntry?.checkoutDetail?.startRange}} </td>
                <td style="display: table-cell;"> {{productEntry?.checkoutDetail?.endRange}} </td>
              </tr>
            </tbody>
          </td>
        </tr>
      </ng-container>
    </tbody>
  </table>
</div>
.block-table {
  display: table;
  overflow-x: scroll;
  max-height: 448px;
  margin-bottom: 0px;
}

Answer №1

Make sure to add a colspan of 2 to the table cells where you want them to span (in this case, it looks like you need it to span 10 columns).

<!DOCTYPE html>
<html>

<head>
  <style>
    table,
    th,
    td {
      border: 1px solid black;
    }
  </style>
</head>

<body>

  <table>
    <tr>
      <th>Monthly Savings</th>
    </tr>
    <tr>
      <td colspan="2">January</td>
    </tr>
    <tr>
      <td colspan="2">February</td>
    </tr>
  </table>

</body>

</html>

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 delete a CSS class from an element?

Is there a way to remove the "ui-widget-content" class from the code below? It appears in multiple places throughout my code. Here is an example snippet: <pre> <form id="clientForm"> <div id="clientData"> <div id="gbox_grid_1" class=" ...

What's the best way to update the value of an angular field upon submission?

Could someone please provide instructions on how to update the myName variable when the "submit" button is pressed? Thank you! app.js: app.controller('SomeController', ['$scope', 'emails', function($scope, emails) { emails ...

What causes the gap between a parent div and inner div in react components?

I have a relatively simple React component that I'm working on. Even though I am quite new to React, I have tried various methods to eliminate the white space issue but so far have been unsuccessful in determining what is causing it. Negative margin s ...

The cart icon is not visible in the responsive mode

There seems to be an issue with my cart icon not displaying in the navbar toggle when the display size is reduced. I am currently using Bootstrap 5 for the navbar. I can navigate to the cart page by clicking on the toggler, but the icon itself is not visi ...

Safari maintains the visibility of the placeholder when altering the value of a field using Javascript

Try running the code in Safari by visiting this link: https://jsfiddle.net/gkatsanos/2355m5ds/ In Safari, I noticed that when I change the .val() of an input field without manually focusing on it, the placeholder text remains visible. https://i.sstatic.ne ...

Clearing data in a JQuery DataTable after loading it with PHP

Once the table is loaded with data, it seems to clear the information after a few milliseconds and displays a row with the message "No matching records found" https://i.sstatic.net/UPEwC.gif HTML Code <table id="table"> <thead> & ...

Displaying information in Angular2

I'm currently facing an issue where I am unable to display certain information from my API in my view, even though the console is showing me that the necessary data is being retrieved. Below is a snippet of my Angular service: getById(id){ retu ...

Blinking Effect of New Element in JQuery ListView

I'm attempting to implement AJAX functionality in a JQuery listview that will make flash yellow, but unfortunately I am having trouble getting it to work. Could someone provide me with some guidance? http://jsfiddle.net/zFybm/ ...

Building a responsive image gallery modal using AJAX in Laravel platform

How can I fix the issue of the modal content briefly appearing when I load my page? I am trying to create an image gallery where a modal opens when an image is clicked. Here is the code in my view.blade.php: <script> $(".li-img").click(function ( ...

Troubleshooting: Why is my CSS background image URL not displaying?

I'm struggling to understand why the background image is not showing up. However, when I use content:url(), it does appear. The issue with using content:url() is that I can't control the size of the image. Below, you will find the complete code f ...

Click to dynamically change the input number variable

I'm in the process of creating a special calculator, where you input the number of years into a field, hit submit, and see different results displayed below without the page reloading. All my calculations are working properly at the moment. However, ...

What is the best way to ensure the content div fills all available space? (JQM compatibility concerns)

Currently, I am facing an issue with displaying a pdf in an iFrame within my app. The problem lies in the fact that the iFrame does not occupy the entire space between the header and footer divs on the page. I am utilizing Jquery Mobile 1.1.0 for the theme ...

Check out the page design for section one!

I have been attempting to create a link to a specific section on a one-page website. Sometimes it works oddly, but most of the time it gets stuck at the section I clicked on and then manual scrolling does not function properly. From what I've researc ...

The Owl carousel seems to be malfunctioning as there are no error messages displayed and the div containing it disappears unexpectedly

I'm having an issue with Owl carousel. I've included the necessary owl.carousel.css, owl.carousel.js, and owl.theme.css files. Created a div with the class "owl-carousel", and called the function $(".owl-carousel").owlCarousel();. However, after ...

Content that refuses to stretch

Lately, I've been working on making sure my footer stays at the bottom of the page while allowing the middle content to stretch so that the footer placement will be correct regardless of the resolution the website is viewed in. It has been a bit sinc ...

When I try to alter HTML using JS, I encounter an undefined error related to AngularJS

Using this specific function: function adjustContent(elemento){ if (document.getElementById(elemento).innerHTML.indexOf('&#10004;')>0){ document.getElementById(elemento).innerHTML=document.getElementById(eleme ...

CSS class malfunction - various classes with identical functions

I'm new to the world of web development and design, embarking on a journey to learn all I can in these fields. Recently, I attempted to create unique hover styles for each menu button within my CSS classes-based menu list. However, I encountered an i ...

Scrolling the Html5 canvas smoothly without the need for constant re-rendering

Is it feasible to achieve smooth panning on an HTML5 canvas without the need for rerendering? Are there any examples of code that demonstrate this functionality? Furthermore, is it also possible to apply the same technique for zooming? I am experiencing ...

Having difficulty formatting a div using HTML/CSS in a React application

As I embark on my journey to learn HTML/CSS, I am experimenting with different examples. Currently, I am struggling to create a div that resembles what I envision due to the content being 'glued' together. I have attempted various methods, but n ...

Automatically focus on input when scrolling reaches a specific element using jQuery

I have been utilizing a jQuery plugin called Waypoints to handle scroll actions. My goal is to focus on the first input element of a section that is currently visible on the screen and then shift the focus to the input of the next respective sections as t ...