Overflow and contain a flex item within another flex item

I am facing a challenge where I need to prevent a flex-child of another flex-child from overflowing the parent, ensuring it does not exceed the screen height or the height of the parent (which is also a flex-child).

Here's the CodePen link for reference.

I have attempted to replicate the HTML structure in line with the Vue project I am working on, and this represents the current layout I have.

Objective: The div element with class=card-body, containing multiple smaller v-card elements, is itself a child of a flex element. My goal is to ensure that it does not overflow the screen but instead gets an overflow setting. I haven't come across a solution that addresses this specifically. I prefer avoiding the use of calc as I want the flexbox to handle it dynamically, if possible.

Below is the outlined HTML structure:

<div id="app">
  <v-app id="inspire">
    <v-app-bar app dense color="primary">
      <v-toolbar-title class="white--text">
        App Title
      </v-toolbar-title>
    </v-app-bar>
    <v-content>
      <div class="d-flex flex-column full-height">
        <!-- TOOLBAR AND SHIZZ -->
        <v-row no-gutters class="flex-grow-0 flex-shrink-1">
          <v-col cols="12">
            <v-toolbar color="secondary" dense>
              <v-toolbar-title class="white--text">
                Some title
              </v-toolbar-title>
            </v-toolbar>
          </v-col>
        </v-row>

<!-- Content -->
          <v-card
    color="column"
    class="d-flex flex-column flex-grow-1 ma-4"
  >
    <v-card-title class="title-1">
      LMAO

      <v-spacer></v-spacer>
      <!-- Menu Component for column -->
      ICON
    </v-card-title>

    <div
      class="d-flex flex-wrap justify-center card-body ml-3 mr-1"
      :class="$vuetify.theme.dark ? 'card-body-dark' : 'card-body-light'"
    >
      <v-card
        v-for="item in 50"
        :key="item"
        class="mr-4 mb-3"
        :color="$vuetify.theme.dark ? 'card lighten-1' : ''"
      >
        <v-card-text class="title">
          Omae Wa Mou Shindeiru! Omae Wa Mou Shindeiru!
        </v-card-text>
      </v-card>
    </div>
  </v-card>

      </div>
    </v-content>
  </v-app>
</div>

The CSS styling used is as follows:

html,
body {
    overflow-y: auto;
    width: 100%;
    height: 100%;
}

.full-height: {
  height: 100% important;
}

.card-body {
  overflow-y: auto;
  max-height: 100%;
}

Answer №1

By some stroke of luck, I stumbled upon a simple solution that worked wonders without me fully grasping the mechanics behind it. To be honest, it was all trial and error.

All it took was using: flex-basis: 0

I've updated the CodePen for you to take a look

Check out the revised CSS below:

html,
body {
    overflow-y: auto;
    width: 100%;
    height: 100%;
}

.full-height {
  height: 100% !important;
}

.card-body {
  overflow-y: auto;
/*   max-height: 100%; */

/*   THIS IS THE KEY */
  flex-basis: 0;
}

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

The box inside a MUI TextField input is consistently visible

My form utilizes MUI Form within a Dialog, but I am facing an issue where the TextField always displays with the border of a filled variant instead of the standard look. Additionally, when trying to integrate an Input from the NextUi library, I encountered ...

Aligning two images vertically using the display: table-cell property

I'm trying to align two images vertically using CSS' display: table-cell property, but it doesn't seem to be working even after specifying the height. <div style='display: table;height:500px'> <div style=' displa ...

The CSS list formatting does not seem to be compatible with Bootstrap 4

For my website, I am working on creating a table using the list method along with CSS. However, I encountered a problem where the table is not displaying correctly when Bootstrap CDN is applied. Removing Bootstrap CDN resolves the issue, but I need to keep ...

Emphasizing the content of the text file with the inclusion of span tags

I am relatively new to working with angular js and javascript. I have a document or text file that looks something like this: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dumm ...

What is the method to send an email with an embedded image using C# without the presence of ATT00001.bin file

Currently, I can successfully send emails using SMTP in C# and even include images as LinkedResource. However, the issue arises when recipients receive emails with ATT0000X.bin files attached. How can I prevent these bin files from being included in the em ...

The image is failing to animate according to the PNG sequence function

Enhanced Functionality: Upon clicking the "Tap Here" image button, a function called "GameStart()" is triggered. This function ensures that the main image "Star" descends down the page from the top through an animated sequence using png logic. The propose ...

Looking to showcase a .tif image in your Angular project?

This code is functioning properly for .png images. getNextImage(imageObj:{imageName:string,cityImageId:number,imgNumber:number}):void{ this.imgNumber= imageObj.imgNumber; this.imagePath=`assets/images/${imageObj.imageName}.png`; this.cityIma ...

Tips for enabling a flexbox item to extend beyond its container

While attempting to utilize flexbox for creating a navbar with the logo in the center, I encountered an issue where the logo wasn't able to overflow from above and below the navbar. I experimented with squeezing in and positioning the element, but it ...

Why does adding to an array in the Vuex store replace all existing values with the last entry?

Utilizing vuex-typescript, here is an example of a single store module: import { getStoreAccessors } from "vuex-typescript"; import Vue from "vue"; import store from "../../store"; import { ActionContext } from "vuex"; class State { history: Array<o ...

What are effective ways to design a dialogue or conversation with CSS styling?

Looking to create a design similar to this one, but unsure of the terminology: https://i.sstatic.net/4QRcw.png I am open to different approaches for the layout, but possibly something along these lines: https://codepen.io/nachocab/pen/LaBwzw .containe ...

Experience inadequate test coverage while conducting unit tests in Vue.js

I'm currently working on Vuejs unit testing using karma+mocha+chai+webpack and aiming to achieve code coverage with istanbul. However, I've encountered an issue where importing certain utility functions or components into the component being tes ...

The addition operation in JavaScript seems to be malfunctioning as it is not adding up my values

After encountering an issue with calculating the number of payments, I discovered that the addition operator was not functioning as expected. Instead of summing up values, it was treating them as strings. For instance, when trying to add 3 and 5, the out ...

Create a stylish frame for designated rows within a table

Col1 Col2 Col3 Col4 Col5 Col6 Row11 Row12 Row13 Row14 Row15 Row16 Row21 Row22 Row23 Row24 Row25 Row26 Row31 Row32 Row33 Row34 Row35 Row36 Looking for a way to add a border around rows with matching values in the first column, or around a specif ...

Issue with the positioning of the datepicker is not functioning properly

I'm currently facing an issue with the position of a date picker plugin from jquery. The search box on my website allows users to select a range of dates using the date picker, but when enabled, the date picker appears at the bottom left corner of the ...

What is the process for transferring a JavaScript file (containing multiple functions) from the server to the client side?

I am looking for a way to hide the server-side functionality from the end user in order to maintain privacy. I have not been able to find a solution for this issue thus far. Currently, I have a .js file containing functions that are used within an html5 f ...

The functionality of the .toggle method is limited to only being effective 1.5

I'm having an issue with making an image popup using the .toggle function in javascript. It seems to work initially, but then only works partially after that. When I click on the image, it opens as expected. However, when I try to close it by clickin ...

Press the list button to reveal an enlarged box

Each item on this list contains a hidden box that should be shown after it is clicked. However, the issue arises when expanding one item causes other items to expand as well. Refer to the image for clarification: Image Link Is there a way to only expand ...

What is the code to incorporate a color using PHP?

Question: Is there a way to indicate approval with green color and decline with red color? I've searched for a solution but couldn't find one. PHP Code: <?php if(isset($_POST['approve'])) { $msg = "Approved"; ...

Place the child DIV at the bottom of its parent DIV

I've searched through open questions but couldn't find a solution. The code snippet in question looks like this: ... <div style="some height"> <div style="some width"> .......and so on.. .. < ...

Tips for switching the background image in React while a page is loading?

Is there a way to automatically change the background of a page when it loads, instead of requiring a button click? import img1 from '../images/img1.jpg'; import img2 from '../images/img2.jpg'; import img3 from '../images/img3.jpg& ...