Ensure that the child div completely fills the entire width of its parent container,

My table contains another table within each row. I have implemented scroll overflow for the mobile view, but this causes the rows to not fill the available space and lose their background when scrolling.

I have experimented with using width: fit-content and min-width: 100%, but I have not achieved the desired result of having the rows fill the entire available space with equal width.

I am looking to ensure that each row has the full width of its parent container.

.container {
  max-width: 700px;
  margin: 0 auto;
  background: #FFF;
  padding: 1rem;
  border-radius: 1rem;
}

.table1 {
  overflow-x: auto;
  border: 1px solid #e0e0e0;
  padding: 0.5rem;
  border-radius: .25rem;
}

.table1__head {
  display: flex;
  gap: 32px;
  align-items: center;
  padding: .5rem;
}

.table1__head>div {
  flex: 1 0 120px;
  min-width: 120px;
}

.table1__body__row {
  border: 1px solid red;
  padding: .5rem;
  border-radius: .25rem;
}

.table1__body__row:not(.table1__body__row:last-child) {
  margin-bottom: 1rem;
}

.table1__body__row__cols {
  display: flex;
  gap: 32px;
}

.table1__body__row__cols>div {
  flex: 1 0 120px;
  min-width: 120px;
}

.table2 {
  margin-top: .5rem;
  border: 1px solid #e0e0e0;
  padding: 0.5rem;
  border-radius: .25rem;
}

.table2__head {
  display: flex;
  gap: 32px;
  align-items: center;
  padding: .25rem .5rem;
}

.table2__head>div {
  flex: 1 0 120px;
  min-width: 120px;
}

.table2__body__row {
  display: flex;
  gap: 32px;
  border: 1px solid blue;
  padding: .5rem;
  border-radius: .25rem;
}

.table2__body__row>div {
  flex: 1 0 120px;
  min-width: 120px;
}
<div class="container">
  <div class="table1">
    <div class="table1__head">
      <div>item 1</div>
      <div>item 2</div>
      <div>item 3</div>
      <div>item 4</div>
      <div>item 5</div>
      <div>item 6</div>
    </div>
    <div class="table1__body">
      <div class="table1__body__row">
        <div class="table1__body__row__cols">
          <div>table value item 1</div>
          <div>table value item 2</div>
          <div>table value item 3</div>
          <div>table value item 4</div>
          <div>table value item 5</div>
          <div>table value item 6</div>
        </div>
      </div>
      <div class="table1__body__row">
        <div class="table1__body__row__cols">
          <div>table value item 1</div>
          <div>table value item 2</div>
          <div>table value item 3</div>
          <div>table value item 4</div>
          <div>table value item 5</div>
          <div>table value item 6</div>
        </div>
        <div class="table2">
          <div class="table2__head">
            <div>item 1</div>
            <div>item 2</div>
            <div>item 3</div>
            <div>item 4</div>
            <div>item 5</div>
            <div>item 6</div>
            <div>item 7</div>
          </div>
          <div class="table2__body">
            <div class="table2__body__row">
              <div>table value item 1</div>
              <div>table value item 2</div>
              <div>table value item 3</div>
              <div>table value item 4</div>
              <div>table value item 5</div>
              <div>table value item 6</div>
              <div>table value item 7</div>
            </div>
          </div>
        </div>
      </div>
      <div class="table1__body__row">
        <div class="table1__body__row__cols">
          <div>table value item 1</div>
          <div>table value item 2</div>
          <div>table value item 3</div>
          <div>table value item 4</div>
          <div>table value item 5</div>
          <div>table value item 6</div>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

To improve the layout, consider adding the following CSS code to the .container class.

.container {
  max-width: 700px;
  margin: 0 auto;
  background: #FFF;
  padding: 1rem;
  border-radius: 1rem;
  display: table; // Add this line for better layout
}

// Rest of the CSS code for tables and styling goes here

<div class="container">
  <div class="table1">
    // HTML content for tables and rows here
  </div>
</div>

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

Use jQuery to swap out two div classes within a table cell (TD) if they are

Although I'm making progress, I must confess that jQuery and CSS are not my strong suits. The objective: To create a dynamic div within a table data cell for a calendar feature. The content of the div varies based on the date range input. A filled d ...

Animation that increments to a predetermined value

I'm trying to create a counter animation that dynamically animates a value calculated by the checkboxes selected. The calculation is working fine, but the animation is not happening. http://jsfiddle.net/dbtj93kL/ $('input[type="checkbox"]&apo ...

Javascript: Troubleshooting Unexpected Variable Behavior in HTML Code

My issue is as follows: I am attempting to retrieve text from a JSON file in my HTML. In the header of my HTML, I have linked a tag with the following code: var language = ""; var langDoc = null; //Function to change the value function setLang() { v ...

What is the best way to ensure that the width of a div fills its parent container?

I need my divs(.give, .sep, .take) to completely fill the width of its parent container (.trade). This is the HTML code: <div class="trade"> <div class="give"></div> <div class="sep"></div> ...

What is the reason tailwind does not take precedence over locally defined styles?

I've been experimenting with changing the default text color using Tailwind CSS, but for some reason, it's not taking effect. I've noticed that Bootstrap is able to override the default style without any issues. I'm fairly new to Tailw ...

Do you want to reset the validation for the paper input?

I am encountering an issue with a paper-input element in my code. Here is what it looks like: <paper-input id="inputForValidation" required label="this input is manually validated" pattern="[a-zA-Z]*" error-message="letters only!"></paper-input&g ...

How to design a bell curve using CSS styling

Exploring CSS shape design, I am aiming to create a classic bell shape reminiscent of the holiday season. While the top and bottom balls are not essential to my design, here is the basic outline I'm striving for: This is what I have been able to achi ...

Steps for printing a web page with a custom stylesheet instead of the default print.css file

I have a print.css file that handles printing website pages, but I now want to create a basic-print.css file specifically for printing out basic information. How can I add a button to the page that triggers the print functionality using basic-print.css ins ...

Navigating with hashtags in Angular2 and anchors does not change the page position

I recently came across a helpful post that showed me how to append a fragment to the URL. Angular2 Routing with Hashtag to page anchor Although the fragment is successfully added, I'm encountering an issue where the page does not scroll to the speci ...

Toggling forms with HTML <select> elements: A step-by-step guide

In the process of creating a web application, I am faced with the task of registering users based on their specific category. To accomplish this, I have incorporated a combo-box where users can indicate their user type. My objective is to display an appro ...

Tips for aligning a custom icon to the left in a Jquery mobile header

I have successfully implemented a custom icon in the header, but it is currently displaying in the center. How can I adjust it to be positioned on the left side instead? <div data-role="header" data-theme="a"> <h3> ...

What is the method in PHP to send an HTML file along with a value in response to a POST request?

I have a PHP file where I want to include a dropdown list and submit button. The dropdown list should display filenames for the user to choose from. Once the user selects a filename from the dropdown list and clicks the submit button, the PHP file should r ...

Modify the text color upon clicking with a TouchableOpacity component

Would appreciate help from experienced coders. I'm just starting out with coding and React. My goal is to be able to change the text color with a click, and then change it back to the original color with another click. function handleColorChange() { ...

Integrating Vimeo videos into Angular applications

I am attempting to stream videos using URLs in my Angular application. Every time I try, I encounter the following error: Access to XMLHttpRequest at 'https://player.vimeo.com/video/548582212?badge=0&amp;autopause=0&amp;player_id=0&amp;ap ...

What is the process for activating JavaScript and embedding it into an HTML document?

I am currently utilizing a JavaScript API that contains several functions. How can I incorporate it into an HTML file? One of the functions, "api.ping()", performs well on PowerShell, but I am encountering difficulties with displaying it on an HTML file. ...

Retrieving the visible text from a webpage with the help of selenium and BeautifulSoup

I am looking to extract all visible content from a specific webpage, like for instance this page. I am currently utilizing a headless Firefox browser remotely using Selenium. The code snippet that I have implemented is as follows: driver = webdriver.Remo ...

In order for Angular forms to be considered valid, they must fall into one of two form

I am attempting to create a dynamic angular form where the user must enter either A or B. A represents a unique identifier, while B consists of a set of values that correspond to that identifier. My goal is to validate the form as valid if either A is ente ...

An easy way to enable mobility for BootstrapDialog on mobile devices

Currently, I am utilizing the library available at https://github.com/nakupanda/bootstrap3-dialog in order to create a dialog box. However, my issue arises when viewing the dialog on mobile devices where it exceeds the screen size. On desktops, adjusting t ...

Learn how to display a "not found" message in a React.js application

I have a piece of code where I am sending a post request to an API and retrieving all the data from the API in a table. I am trying to find currency data based on the currency name, if found I display the data in a div, if not found I want to print "not ...

Clicking on a button within the parent element will enable you to remove the parent element multiple times with the use of VanillaJS

Within a ul element, each li contains multiple elements in the following structure: <ul> <li> <div> <p>some text </p> <button>delete</button> <div> </li> <li> ...