The parent container refuses to conform to the dimensions of the child container when using a grid layout

When it comes to building a basic website, I am facing an issue where the parent div does not adjust to the content inside. Everything works fine when there is some content, but as soon as I set the child div to display: grid, the height of the parent div remains fixed at 100vh, even when the grid items overflow downwards. Below is the code snippet:

* {
  padding: 0;
  margin: 0;
}

.container {
  min-height: 100vh;
  height: auto;
  display: flex;
  flex-direction: column;
}

.one {
  background: grey;
}

.title {
  text-align: center;
  background: turquoise;
  flex: 0 1 auto;
}

.content {
  flex: 1 1 auto;
  background: red;
  font-size: 5rem;
  justify-content: center;
  display: grid;
  grid-template-columns: repeat(2, 40%);
  grid-template-rows: repeat(4, 40%);
  column-gap: 5rem;
  row-gap: 5rem;
}

.content-object {
  background: url("Project4.jpg");
  background-position: center;
  background-size: cover;
}
<div class="container one">
  <div class="title">
    <h1>TEST</h1>
  </div>
  <div class="content">
    <div class="content-object"></div>
    <div class="content-object"></div>
    <div class="content-object"></div>
    <div class="content-object"></div>
    <div class="content-object"></div>
    <div class="content-object"></div>
    <div class="content-object"></div>
    <div class="content-object"></div>
  </div>
</div>
<div class="container two">

</div>

Answer №1

The issue at hand is that

grid-template-rows: repeat(4, 40%);

Using 40% for the rows is causing problems. It would be better to use px instead.

Additionally,

row-gap: 5rem;

is excessive and should be reduced.

Check out this demo codepen link

I have also included padding on the top and bottom of the container.

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

Adjust scrollbar thumb size using CSS

I am looking to customize my scrollbar with a larger thumb size compared to the track. While I can adjust the color and other properties easily, I am struggling to change the sizes of the thumb and track separately. .custom_scrollbar::-webkit-scrollbar { ...

Incorporating a CSS file within a JSP page

I've been struggling to get my '.jsp' file to utilize a '.css' file that I created. Initially, I stored the '.css' file in the 'WEB-INF' folder but discovered that this folder is not accessible publicly. So, I m ...

Bootstrap arranges checkboxes into three evenly spaced columns and centers them within a form

Having trouble organizing my checkboxes into 3 columns and centering them within the form perfectly. Current layout: Click here for image Desired look: Click here for image HTML: ` <form action="/signup" method="POST" ...

What is the best way to align an image with the background of a div element?

Currently, I am attempting to create a page header that includes an image. To achieve this, I am using a div: <div id = "header"> </div> To set the background image of the div, I have added the following CSS: #header{ background-image: u ...

What is the best way to retrieve all the information from a JSON file using a foreach loop in Laravel?

My Laravel Controller public function index() { $get=Storage::disk('public')>get('Philippines.json'); $json = json_decode($get, true); return view('BarangayFolder.index')>with('json& ...

JS receiving a reference to an undefined variable from Flask

I referenced this helpful post on Stack Overflow to transfer data from Flask to a JS file. Flask: @app.route('/') def home(): content = "Hello" return render_template('index.html', content=content) HTML <head> ...

When inline-block elements wrap onto a new line, they expand to full width

Upon my realization, an inline-block element will expand to 100% width if there are more child elements than can fit on one line: <div style="background-color:red;padding:5px"> <div style="display:inline-block;background-color:green;padding:5 ...

Guide to incorporating flash into a form similar to the method used on http://www.mediafire.com

I'm looking to integrate a flash upload feature into my index file, but I'm not sure how to do it. Here is the link to the flash uploader: . I want it to work similar to how uploading works on when you click on UPLOAD. Thank you for any assistan ...

What methods can be used to optimize web page designs for varying levels of user privilege?

When creating web pages for users with varying levels of access and privileges, what is the most effective approach to take? And also, how can we ensure the safety of our design? 1) Should we create separate pages for different user levels/privileges? Or ...

The Bootstrap-vue b-table responsive feature does not support recognition of the lg or xl values

I need help keeping the horizontal scroll bar at the bottom of my table without having to scroll all the way down. When I use the responsive property like this: <b-table :responsive="md" :items="details" > The values md and ...

Vue Filtering and Pagination Implementation

In Vue pagination, how can you control the number of array objects to be displayed based on a user-selected amount like 10, 15, or 25? I successfully implemented rendering 10 items per page and it's functioning smoothly. ...

Toggle the visibility of text boxes based on the checkbox selection

After doing some research, I decided to revise the question after receiving feedback that it was causing some concern. When a checkbox is clicked, the content of the corresponding div should be visible and vice versa. How can I achieve this? Thank you. JQ ...

Guidance on creating cookies using Angular

I have been attempting to set a cookie using the method outlined in this post. However, despite following the instructions, I seem to be missing a crucial step as the console only displays "undefined". Below is the complete HTML content that I am using: & ...

Striking a line through the hyperlink tag

I am attempting to create a crossed-out line above the content of an a tag for decorative purposes. The line should stretch across the entire width without intersecting with the actual text within the tag. This is my desired outcome: https://i.sstatic.ne ...

Vue.js - Problem with loading image on screen

Although I have experience with React, I am currently facing the challenge of using Vue for a code assessment for the first time. My struggle lies in creating a reusable image component with WAI-ARIA accessibility. Despite my efforts, I cannot get the imag ...

Getting data from a Django template using the Django template language and passing it to another method

Is there a way to access data from my template in a different method in views.py after pressing a button? Here's a brief example of what I'm trying to accomplish: TEMPLATE: (test.html) <!DOCTYPE html> <html lang="en"> <head> ...

Determine the variable height of a div containing dynamic content in order to execute a transform

Looking to create a dynamic container that expands when a button/link is clicked? The challenge lies in achieving this expansion effect with a smooth transition. By using the height: auto property, the container can expand to fit its content, but incorpora ...

What is the best way to assign a numeric variable to the value attribute of an HTML form input?

Is there a way to assign a numeric value to the value attribute of an HTML form input element using a variable? I understand that the value attribute automatically gets converted to a string. How can I make sure the variable is read before being converted? ...

Explore the Codrops website with the help of our convenient tour feature and

CoDrops offers a website tour feature created with jQuery, which can be found at this link: http://tympanus.net/Development/WebsiteTour/ However, there is an issue when you click on "Start the tour". It will initially show a Next button, which then change ...

What could be causing this jQuery selector to not select any elements?

Here's a simple question with some code that needs troubleshooting: $insides = $('<thead><tr><th><!--Blank space --></th></tr></thead><tbody><tr class="green-row"><td>Opportunities to D ...