children in CSS grid expanding beyond grid boundaries

I am facing a challenge with my grid layout where the children's content needs to be scrollable. The grid is sandwiched between a header and footer, as illustrated below:

<div class="app">
  <div class="header">
  Header
  </div>
  <div class="grid">
    <div class="first card">
      <div>
        Card Header
      </div>
      <div class="content">
        ...
      </div>
    </div>
    <div class="second card">
      <div>
        Card Header
      </div>
      <div class="content">
        ...
      </div>
    </div>
    <div class="third card">
      <div>
        Card Header
      </div>
      <div class="content">
        ...
      </div>
    </div>
  </div>
  <div class="footer">
  Footer
  </div>
</div>

I want to make sure that the grid does not exceed the viewport size. The footer should always stay visible, and I don't want the main viewport to have a scrollbar (only the individual card contents should scroll).

Currently, I have set the overflow property to auto for the contents:

.content {
  overflow-y: auto;
}

However, the only way I can get them to scroll is by setting a fixed height or max-height, which I do not want. I want the content to take up space without causing the main viewport to require scrolling. I've tried adjusting the max-height but haven't found a solution yet. You can view my code in this fiddle:

https://jsfiddle.net/ja94t0m0/39/

In the current setup, the footer is slightly misplaced, and the grid items extend beyond it. I am seeking assistance in fixing both of these issues.

Answer №1

If you want to achieve this effect, consider utilizing CSS flexbox

The Flexbox Module, commonly known as flexbox, provides a one-dimensional layout system with powerful alignment capabilities and efficient space distribution between elements in an interface. This overview highlights the key features of flexbox, which we will delve into further in subsequent guides.

I recommend using Autoprefixer CSS for this task

The autoprefixer tool makes use of browser popularity data to determine the support for vendor prefixes in different browsers. It then organizes and removes unnecessary prefixes. This can be particularly useful when dealing with prefixes for: animations, transitions, transformations, grids, flex, flexbox, and more.

Prior to applying Autoprefixer CSS

html,
body {
  height: 100%;
  margin: 0
}

.box {
  display: flex;
  flex-flow: column;
  height: 100%;
}

/* Additional CSS code provided */
...

After implementing Autoprefixer CSS

html,
body {
  height: 100%;
  margin: 0
}

.box {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-flow: column;
          flex-flow: column;
  height: 100%;
}

/* Updated CSS code after Autoprefixer */
...

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 is the best way to enclose text within a border on a button?

I am trying to create a button with a colored border around its text. Here is the code for my button: <input id="btnexit" class="exitbutton" type="button" value="Exit" name="btnExit"></input> Although I have already added CSS styles for the ...

Switch out the view div element with ui-router

Currently, I am utilizing Angular ui-router to manage various views in the following manner: <div ui-view="header"></div> <div ui-view="nav"></div> <div ui-view></div> Upon Angular loading, the divs are automatically p ...

What is the best way for me to make sure the element overflows properly?

How can I make the contents of the <div class="tags> element cause overflow so that one can scroll its contents instead of the element simply extending in height? I've experimented with different combinations of overflow-y: scroll and min- ...

What causes HTML validator errors in all head meta-tags?

After running my HTML through a validator, I was shocked to discover around 80 errors even though the site appeared to be functioning properly. Here is an excerpt of the code: <!DOCTYPE html> <html lang="da-DK"> <head> <meta charset=" ...

Is there a way to create a dropdown menu that appears to emerge from behind a button?

I am struggling with the stack order of my dropdown menu. Despite using z-index, it appears in front of the button instead of behind it. I want it to look like it is coming out from behind the button. Here is my code: .subnav-wrapper { position: relat ...

I'm having trouble modifying the border color of a TableCell component in material-ui

I am struggling to change the border color of a table cell. Despite numerous attempts, I have been unsuccessful in my efforts. Can someone please assist me with this? const customTheme = createTheme({ overrides: { MuiTableCell: { root: { ...

What is the fastest way to add an email subscription form to my website without needing to configure a database?

Would it be possible to integrate a sign-up text box on our site for users interested in receiving launch notifications? Any suggestions on the most effective method to implement this feature? EDIT: Our current use of Prefinery has limitations as we cann ...

Creating an illustration with HTML5 from an image

Is it possible to draw on an image by placing a canvas on top of it? I am familiar with drawing on a canvas, but I am facing an issue where clicking on the image does not trigger the canvas for drawing. How can I resolve this? This is how my HTML looks: ...

How can I trigger a PHP function from within an HTML onClick() event?

While I have come across a response on stackoverflow regarding form submission, my query pertains to a different implementation. I am in need of calling a function that registers a variable in $_SESSION[], and then redirects to another page (html/php). I ...

Changing the position of an image can vary across different devices when using HTML5 Canvas

I am facing an issue with positioning a bomb image on a background city image in my project. The canvas width and height are set based on specific variables, which is causing the bomb image position to change on larger mobile screens or when zooming in. I ...

Having Trouble with Your CSS Styles?

After working with HTML and CSS for over 5 years, I find myself stumped by this particular issue. At the provided URL, there is a single div in that container with an ID of Clarity. The CSS rules I have implemented are as follows: #clarity { text-align: ...

Modifying the dimensions of mat-card in Angular Material

https://i.stack.imgur.com/CP16N.png I am struggling to make both components the same height, similar to the left form. I have tried adjusting margins and padding but nothing seems to work. Below is the HTML code for the parent element: <mat-tab label= ...

What's preventing my Angular list from appearing?

I am currently developing an Angular project that integrates Web API and entity framework code first. One of the views in my project features a table at the bottom, which is supposed to load data from the database upon view loading. After setting breakpoin ...

What's the best way to ensure uniform card height in Material-UI?

Is there a way to ensure consistent card height in Material-UI without setting a fixed height? I want the card heights to dynamically adjust based on content, with all cards matching the tallest one on the website. How can this be achieved while also addin ...

What is the best way to target and manipulate the transform property of multiple div elements in JavaScript?

Looking at this code snippet, my goal is to have all the boxes rotate 180deg with a single click, without needing to apply different ID names: function rotateAllBoxes() { var boxes = document.getElementsByClassName("box"); for (var i = 0; i < box ...

Having trouble implementing table row selection with semantic-ui table

I am currently in the process of adopting Semantic-UI, but I am encountering some issues. Specifically, I am struggling to make row selection work in a table. Below is the sample HTML I am using from Semantic-UI: <table class="ui selectable celled tab ...

The button now has a stylish 5px border, making it slightly larger in size. However, it seems

How can I add an active class with a 5px border-bottom on a button without increasing the button size by 5px? The box-sizing property is not working for me. Is there a simple solution to achieve this? *, *:after, *::before { -webkit-box-sizing: border ...

Attaching dynamic data to a specific element within an array

I have successfully created a demo where elements can be dropped into a specific area and their top and left values are displayed. I have also added functionality to remove dropped items and move them between different blocks. However, I am encountering so ...

JQuery validation and qTip2 - Remains visible even after successful validation

Struggling with getting both libraries to work together has been a challenge for me, but I'm almost there now! Initially, I attempted the suggested method: Create the form Set validation rules using escaped name attributes, as RoR automatically set ...

Having trouble getting a dropdown menu to function properly with jQuery

Within my project, I have implemented a menu that transforms into a dropdown menu for smaller screens. Below is the HTML code for this functionality: <select> <option value="index.php" id="home">Home</option> <option value="about ...