flexbox with a table that can be scrolled vertically

I am currently working on creating a scrollable tbody within a flexbox layout.

I have two flexboxes, each containing a table.

When the items in the table overflow, I want to display a vertical scrollbar within the tbody.

However, the tables are within flexboxes that do not have a fixed height.

What steps should I take to enable the vertical scrollbar within the tbody?

.root {
  background-color:green;
  width: 200px;
  height: 200px;
  display: flex;
  flex-flow:column nowrap;
}

.container1 {
  display: flex;
  flex-grow:4;
  background-color:yellow;
}

.container1 tbody {
  overflow: auto;
}

.container2 {
  display: flex;
  flex-grow:3;
  background-color:blue;
}
<div class="root">
  <div class="container1">
    <table>
      <thead>
        <tr>
          <td>name</td>
          <td>age</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="container2">
      <table>
      <thead>
        <tr>
          <td>name</td>
          <td>age</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
        <tr>
          <td>jhon</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

Please feel free to reach out if you require additional information. Thank you.

Answer №1

It is advisable to implement overflow auto in this scenario

Styling suggestion

.container1 {
  display: flex;
  flex-grow:4;
  background-color:yellow;
  overflow:auto;
}

Answer №2

Kindly review the updates I have made!

.root {
  background-color:green;
  width: 60vw;
  height: 30vh;
  display: flex;
  flex-flow:column nowrap;
}

.container1 {
  display: flex;
  flex-grow:4;
  background-color:yellow;
  overflow-y: auto;
}


/* this flexbox is not appearing!! */
.container2 {
  display: flex;
  flex-grow:3;
  background-color:blue;
}
<div class="root">
  <div class="container1">
    <table width="100%">
      <thead>
        <tr>
          <td>name</td>
          <td>age</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
        <tr>
          <td>john</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="container2">
  </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

What could be causing the combined width of the children to exceed that of the parent?

Encountered an issue while trying to create a horizontal scroll using inline-flex. Unable to add padding around the scrolling div due to inconsistencies in child widths causing unexpected behavior. To further investigate and understand the problem, visit ...

The dropdown menu is currently activated, but not the individual items within it

Is there a way to make the dropdown menu active when I click on an item, specifically making the word Services active? How can this be achieved? <nav class="navbar navbar-light navbar-expand-xl"> <a class="navbar-brand" hre ...

Significant contrast in how text is displayed between Chrome and Firefox

Experiencing significant discrepancies in text rendering between Chrome and Firefox. Chrome appears to apply anti-aliasing rules that reduce the text size considerably. Attempts have been made to adjust -webkit-font-smoothing, letter-spacing and word-spac ...

What is the process for adding text before and after a Bootstrap progress bar?

I want to customize the bootstrap progress bar with text at the beginning and end, like this: 5 star ----------------------------------------------- 70% Here is my attempt to achieve this: <link rel="stylesheet" href="https ...

Attempting to evenly distribute items within a div container

My goal is to arrange the items in the container div evenly on a single line. I want them to be spaced out like this: https://i.sstatic.net/kA2zj.png I'm struggling to achieve this layout where the items are on the same line and evenly distributed w ...

JavaScript Auto-Closing Modal Pop-Up in HTML

I am looking to implement a feature similar to what is seen on Banks or American Express websites, where a MODAL Popup notifies users that their session is about to expire. In addition to this, I would like to include an "Auto-Close" Popup event that will ...

The CSS for the UI Grid is malfunctioning

I have been working on creating a grid using UI Grid (recent version of ngGrid) within my current project. However, I am facing some issues with the display. The icons like angle down and row selected icon are not showing up correctly when I include the CS ...

Rotating a CSS div causes the page to scroll horizontally

Currently, I am working on creating a unique design for the footer of my website. However, when implementing it, I encountered an issue that is causing a horizontal scroll (red background added for clarity). https://i.sstatic.net/K4vnV.jpg To address thi ...

The submission of the form is not possible with jQuery

Here is my code: $(document).ready(function(){ console.log("jquery is functioning"); // **** Global Variables **** //starting ingredient number for new ingredients $ing_num = 3; var new_label; var new_input; $("#add_icon").click(funct ...

Is it possible to resize a div based on the width of the window?

Imagine a scenario where it's not possible to change the content of a div, but only its shape and size by using transform: scale(1.4) for instance. To better understand this concept, take a look at This Website and try resizing the window using brows ...

Parallel with one <div> and subsequently another <div>

I have been challenged by HTML and CSS to embrace humility: Attempting to replicate the following design: Here is my effort: <div> <div style="width:800px;"> <div style="float:left;width:25%;background-color:red;">Facility #: COM ...

A vertical line in Javascript extending upward from the base of an element

Is there a way to create a design where an infinite vertical line extends from the bottom of a circle (or in my case, a rectangle) without using css :after or pseudo-elements? I would like the line to be its own element and not limited by the restriction ...

Methods for anchoring an element at the bottom of a square container div

* { box-sizing: border-box; } .publication { display: flex; width: 100%; margin-top: 6%; } .bottom1, .bottom2 { display: flex; flex-direction: column; ...

update the markers on a leafletjs map

I am aiming to create a dynamic map with markers that update every 10 minutes. The marker positions are stored in a spreadsheet document that is regularly updated. After successfully retrieving the data from the spreadsheet and positioning the markers in ...

Creating an interactive flip card using HTML and CSS

I am a beginner in HTML and I'm looking to create a specific element that flips. I have created this file. However, when the first element is flipped (refer to the codepen), the content appears at the bottom (see image). Can someone assist me in ensu ...

Is it possible to customize the Angular Kendo Grid to be non-scrollable and automatically adjust its height to fit the row contents?

I'm trying to create a Kendo Grid in Angular that is Non-Scrollable and adjusts its height to fit the row contents. However, my current implementation is not working as expected, as it still gives me a fixed height. <kendo-grid [data]="propertyVie ...

Adjusting background position using incremental changes through JavaScript

Although I have a strong background in PHP coding, using javascript is a new venture for me so I hope this question doesn't sound naive. My objective is to create a button that, when clicked, shifts the background-position of a specified DIV object b ...

Is it possible to define a multiplication margin using css?

I am trying to place a box in the center of a container, but I am unable to set a static height for the parent element as it may change. This is causing issues with aligning the box perfectly in the middle of the page. Any assistance would be greatly app ...

The uniform height of flex columns was spoiled by a child element with a display setting of flex

CSS: * { padding: 0; margin: 0; box-sizing: border-box; } body { display: flex; background-color: #F5F5F5; } body > header { display: flex; position: fixed; width: 100%; height: 60px; align-items: center; background-color: #373737 ...

Combine going to an anchor, performing an AJAX request, and opening a jQuery-UI accordion tab all within a

My goal is to have the user click on the hyperlink below, which will (1) anchor to #suggestions, (2) navigate to the url suggestions.php?appid=70&commentid=25961, and (3) open the jquery-ui accordion #suggestions. However, I am facing an issue where c ...