Empty space found at the bottom of a webpage while viewing on smaller browser resolutions due to the CSS-Grid layout

Recently, I've been working on designing a website layout using CSS-Grid. Everything seems to be functioning properly and adapting well to different screen sizes until I encountered an issue with scroll bars appearing at very small resolutions. This causes the css-grid to stop stretching over the entire page height, leaving a blank white space at the bottom.

If you want to visualize this problem, try running the provided snippet in a low-height window. In addition, I have included screenshots of how it appears on my browser for reference.

How it looks at normal height:

What happens when the height is reduced:

I attempted adjusting the overflow and min-height properties but was unable to resolve the issue completely. While not critical, I am curious to understand why it occurs. Thank you!

body, html{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
}

.grid-container-1{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 8% 70% auto 8% ;
  grid-template-areas:
  "header1 header1 header1 header1"
  "Cover Cover Cover Cover"
  "Project Project Project Project"
  "Footer Footer Footer Footer"
}

.header1{
  grid-area: header1;
}

.cover{
  grid-area: Cover;
}

.Project{
  grid-area: Project;
}

.Footer{
  grid-area: Footer;
}

.zone {
    cursor:pointer;
    color:#FFF;
    font-size:2em;
    border-radius:4px;
    border:1px solid #bbb;
    transition: all 0.3s linear;
}

.zone:hover {
    -webkit-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
    -moz-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
    -o-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
    box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
}
/* Source: https://paulund.co.uk/how-to-create-shiny-css-buttons */

/* Various Color Background Styles */
.green{
    background: #56B870; /* Old browsers */
    background: -moz-linear-gradient(top, #56B870 0%, #a5c956 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#56B870), color-stop(100%,#a5c956)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #56B870 0%,#a5c956 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #56B870 0%,#a5c956 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #56B870 0%,#a5c956 100%); /* IE10+ */
    background: linear-gradient(top, #56B870 0%,#a5c956 100%); /* W3C */
}

.red{
    background: #C655BE; 
    ...
}

.yellow{
    background: #F3AAAA;
    ...
}

.blue{
    background: #7abcff;
    ...
}
<!DOCTYPE html>
<html>
<head>
  <title>CSS Layout</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <div class="grid-container-1">
      <div class="header1 zone green">
        Header
      </div>
      <div class="cover zone red">
          Cover
      </div>
      <div class="Project zone blue">
        Projects
      </div>
      <div class="Footer zone yellow">
        Footer
      </div>
  </div>
</body>
</html>

Answer №1

Your text size is exceeding the limit of the last row and overflowing from its container.

One possible solution is to adjust the size of the last row to 1fr:

body, html{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
}

.grid-container-1{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 8% 70% auto 1fr;
  grid-template-areas:
  "header1 header1 header1 header1"
  "Cover Cover Cover Cover"
  "Project Project Project Project"
  "Footer Footer Footer Footer"
}

.header1{
  grid-area: header1;
}

.cover{
  grid-area: Cover;
}

.Project{
  grid-area: Project;
}

.Footer{
  grid-area: Footer;
}

.zone {
    cursor:pointer;
    color:#FFF;
    font-size:2em;
    border-radius:4px;
    border:1px solid #bbb;
    transition: all 0.3s linear;
}

.zone:hover {
    -webkit-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
    -moz-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
    -o-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
    box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
}
...
<!DOCTYPE html>
<html>
<head>
  <title>CSS Layout</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <div class="grid-container-1">
      <div class="header1 zone green">
        Header
      </div>
      <div class="cover zone red">
          Cover
      </div>
      <div class="Project zone blue">
        Projects
      </div>
      <div class="Footer zone yellow">
        Footer
      </div>
  </div>
</body>
</html>

Answer №2

If your viewport is too small to accommodate both the header and footer, causing text overflow, a simple solution is to apply overflow: hidden to the zone element for smaller screens. See the demo below:

body, html{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
}

.grid-container-1{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 8% 70% auto 8%;
  grid-template-areas:
  "header1 header1 header1 header1"
  "Cover Cover Cover Cover"
  "Project Project Project Project"
  "Footer Footer Footer Footer"
}
/* Rest of CSS code omitted for brevity */
<!DOCTYPE html>
<html>
<head>
  <title>CSS Layout</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <div class="grid-container-1">
      <div class="header1 zone green">
        Header
      </div>
      <div class="cover zone red">
          Cover
      </div>
      <div class="Project zone blue">
        Projects
      </div>
      <div class="Footer zone yellow">
        Footer
      </div>
  </div>
</body>
</html>

To prevent unnecessary overflow of text and maintain usability, adjust the heights of the header and footer elements by modifying the grid-template-rows property to something like

grid-template-rows: 3em 1fr auto 3em
:

body, html{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
}

.grid-container-1{
  height: 100vh;
  min-height: 100vh;
  min-width: 300px;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 3em 1fr auto 3em; /* CHANGED */
  grid-template-areas:
  "header1 header1 header1 header1"
  "Cover Cover Cover Cover"
  "Project Project Project Project"
  "Footer Footer Footer Footer"
}
/* Rest of CSS code omitted for brevity */
<!DOCTYPE html>
<html>
<head>
  <title>CSS Layout</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <div class="grid-container-1">
      <div class="header1 zone green">
        Header
      </div>
      <div class="cover zone red">
          Cover
      </div>
      <div class="Project zone blue">
        Projects
      </div>
      <div class="Footer zone yellow">
        Footer
      </div>
  </div>
</body>
</html>

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

Preventing Scrollable Div Content from Displaying Behind a Fixed Div using CSS

Seeking help with a message_container division that contains a fixed scrollable message_header division and a scrollable message_body division. The issue I am facing is that the content of the message_body division is appearing behind the fixed div. How ca ...

Tips for creating an input box that only accepts floating point numbers:

I have a custom component - a text box that I am using in two different places. In one location, it accepts integers and in another, floats. For the integer validation (where dataType=2), I have successfully implemented it. However, for the float validat ...

JavaScript event/Rails app encounters surprising outcome

I have encountered a strange bug in my JavaScript code. When I translate the page to another language by clicking on "English | Русский" using simple I18n translation, my menu buttons stop working until I reload the page. I suspect that the issue ...

Executing a JavaScript function within a PHP echo statement

I am completely new to working with AJAX and PHP echo variables or arrays. However, I have managed to successfully display images on my website by passing variables from AJAX to PHP and back. The only problem I am encountering is when I try to call a Javas ...

The canvas surpasses the boundaries of the grid layout

Trying to design a grid layout with 3 columns of content, alongside an .overlay div featuring a particles.js canvas. Having trouble? See my Codepen here: https://codepen.io/radzak/pen/MVQVPQ The goal is for the grid to always occupy 100% of the screen, t ...

Adjust the CSS2D objects' visibility based on their parent THREE.js Group's visibility toggling

In my project using THREE.js, I have successfully added meshes and CSS2DObjects (labels) to a group. When I toggle the visibility of the group, the meshes change visibility as expected. However, the CSS2DObjects' visibility does not change accordingly ...

Leveraging a JQuery plugin to generate dynamic HTML content

Recently, I came across a fantastic JQuery plugin that Stack Overflow graciously provided for everyone to use :) Auto-size dynamic text to fill fixed size container However, I encountered a little challenge while trying to implement this on an HTML eleme ...

The HTML component fails to acknowledge width settings

I seem to be having trouble identifying an issue or perhaps I am misunderstanding something (I am using daisyui + nx + tailwind css + angular). To simplify my problem, let's consider the following scenarios: In the first scenario, I have: <div cl ...

relocate the figcaption below the image on mobile devices

Currently, I am in the process of updating an old website to make it responsive, and I have encountered several challenges along the way. My goal is to have the fig captions displayed on the right side in the desktop version, but underneath the figure in ...

Issues with image sizing on mobile devices

After finalizing my header design, I encountered an issue with the mobile version of the website. The images in the header are not responsive and do not adapt well to different screen sizes. I need assistance converting the header design into functional co ...

Tips for arranging menu items along a curved counter

One of my clients has requested a unique design feature—a curved menu. The menu items are currently represented by red squares, but they should be positioned to follow the curve of the pink squares on the blue bar. How can I achieve this effect? Should ...

The HTML button navigates to an incorrect form

I have developed a program that includes a section for user comments and another section where logged-in users can input their own comments. When a logged-in user writes a comment, they will see a delete button next to it. Clicking on this button should t ...

combine two columns into a single responsive list group item

Using Bootstrap 4, I created an item list and divided it into two columns (see image). However, when I resized the website to a mobile size screen, it displayed like this: https://i.sstatic.net/0iPHm.png My desired outcome is for the list to display in o ...

Retrieving the text from the img tag of a bs4.element.Tag

I have a question that needs to be addressed. My concern involves a list of bs4.element.Tags, similar to the one illustrated in the image below. The issue at hand is filtering out only the href tags that are preceded by an <img> tag. How can this s ...

Deactivate the dropdown menu without triggering any event

I am working on a JSP page and I need to find a way to disable a dropdown list without using an onclick method or event in the dropdown menu itself. <% boolean condition = true; if(condition){ // Here, I need to access 'plc1' ...

Overlay Image on Card, Overflowing into Card Body

I currently have a webpage featuring cards. Each card includes a thumbnail at the top with an overlay. The main content of the card needs to be positioned outside of the overlay, but it ends up overflowing onto it. Take a look at the demo: https://codepe ...

Unable to retrieve element using getElementById with dynamically assigned id

After researching on Google and browsing through various Stack Overflow questions (such as this & this), I have not been able to find a solution. I am currently working on validating dynamically generated rows in a table. The loop and alert functions a ...

Adding tags to a URL using jQuery without causing a page refresh

I am in the process of developing a "builder" page that allows users to choose an element from a dropdown menu and create a webpage. Since we don't have access to a database for this task, I want to save the elements in the URL so it can be shared via ...

Is there a way to remove this annoying double Google search bar?

Looking to replicate the Google home page for a project using HTML and CSS. I'm having trouble with incorporating the highlighted code (as shown in the second picture and identified by bold and italicized text) into my code. When I try to add it, I en ...

javascript strange behavior

I am facing an issue with my code that is attempting to display images based on their height. Strangely, the code seems to work fine when I test it with 2 images, but fails when trying with 3 or more. Check out the site: Upon clicking a menu button, the ...