React NextJS CSS - Setting the section's height to 100% of the parent's height results in taking up 100% of the page's height

I've encountered an issue while transferring my project to NextJS from Create-React-App.

In NextJS, setting the height of a section to 100% is causing it to take up the entire page height instead of adjusting for the header and footer elements. I need the content's minimum height to fit perfectly so that the footer always aligns at the bottom of the screen.

Here's a visual representation of the problem: section

The section extends to 100% of the page height even though there's a header with a minimum height of 5rem and a footer with a minimum height of 20rem.

This is the structure of the HTML: HTML structure

All these elements - Navbar, Section, and Footer - are nested under the same div ("__next") which also has a height set to 100%.

I'm having trouble understanding why the section takes up 100% of the viewport height instead of the available space.

Any assistance on this matter would be greatly appreciated!

Below are some relevant code snippets:

/* Setting the height of all direct children of body (the __next div) */
body > div {
  height: 100%;
}

/* Setting the height of the section */
section {
  height: 100%;

  display: flex;

  align-items: center;
  justify-content: center;
}

Answer №1

To ensure the div's height is set correctly and displayed as a column, I made the following adjustments:

#__next {
  height: 100%;

  display: flex;
  flex-direction: column;
}

As a result, I removed the code below:

body > div {
  height: 100%;
}

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 conceal a menu that automatically scrolls to the content when it is clicked?

Below is a Codepen with a menu that isn't behaving as expected. var menu = document.querySelector('.nav__list'); var burger = document.querySelector('.burger'); var doc = $(document); var l = $('.scrolly'); var panel = $ ...

Master the integration of Flask API with React-Redux by effectively implementing axios

Hello everyone! I am new to the world of React-Redux and I am currently working on a classification app using Flask API with ReactJS as the front-end. However, I am facing some issues when trying to call the API in Redux through the action file. The predi ...

What is the process for updating mesh textures?

I'm sorting out an issue in my React project where I can't seem to access the material property of a mesh I'm working on. Despite seeing the property when logging the object to console, attempting to access it using 'mesh.material' ...

Building a Full-Stack Application with React, Express, and Passport

I'm in the process of setting up a full-stack application that utilizes React and Express JS. For authentication, I have implemented Passport.js but encountered a minor issue... My front-end and back-end are running as separate packages on different ...

What is the best way to monitor a live link in next.js?

I have a sidebar feature in my administration panel that includes various links, some of which are located within a dropdown menu. I am looking to dynamically add an active class to the current link or, if the active link is within the dropdown menu, to th ...

Hello there! I'm currently working on implementing a button that will alter the CSS grid layout

I need help designing a button that can alter the layout of my CSS grid. The grid information is contained within a class called 'container'. My goal is to change the grid layout by simply clicking a button, using either HTML and CSS or JavaScri ...

Is it possible to access the CSS property from an external CSS file even when inline styles are used?

Is there a way to retrieve the css property from an external source using JavaScript or jQuery even if inline styles are applied to the same element? Here's an example: <div id="my" style='left:100px'>some content</div> <styl ...

Enhancing BarGraph and Bars Size in Oracle ADF

We have created a web application using Oracle ADF. The application includes a page with a graph displayed below. Currently, we are looking to enlarge the bar graph by increasing its height, width, and size of the bars themselves. Difficulty 1: While we ...

Error encountered while trying to transform value into a MediaStream object

I am currently working on incorporating the Screen Capture API into my project. You can find more information about it here. I am coding in React JS and encountered an error when trying to implement the following code: After executing the code snippet be ...

Opinion sought: Which is better - creating a CustomWidget or tweaking the CSS? Implementing Surveyjs in conjunction with Next.js and Material UI

Seeking guidance on a current project scenario: Working with a nextjs app using material ui v5 with a custom theme This theme is utilized across multiple apps to maintain consistent look and feel Goal is to create survey forms through the creator tool ...

Error: The default export is not a component compatible with React in the specified page: "/"

I'm facing an issue while building my next app. Despite using export default, I keep encountering an error that others have mentioned as well. My aim is to create a wrapper for my pages in order to incorporate elements like navigation and footer. vi ...

React child component does not refresh upon modification of an array property

In my main application, I have two subcomponents that both receive the same model property. The first subcomponent deals with a number prop from model.myNumberProperty, and the second subcomponent handles an array prop from model.myArrayProperty. When ch ...

The background image is not showing up

I've been grappling with a CSS background-image dilemma that's got me stumped. Here's the situation: CSS #yes { background-image:url("../tick.png"); background-repeat: no-repeat; height: 16px; width: 16px; }​ #no { backg ...

Conceal content in Bootstrap navbar when clicking on #link

I am facing an issue with the navbar-fixed-top element as it is causing content to be hidden from the container. To resolve this common problem, you can add the following CSS code: body { padding-top: 70px; } After applying the above code, the container ...

A step-by-step guide on integrating Azure Cognitive Search within a SharePoint Online SPFx webpart

I haven't had much experience with SPFx recently, so it looks like I'll need to brush up a bit. :) I'm interested in implementing this NPM package: https://www.npmjs.com/package/azure-search Within a simple new SPFx web part: The code ...

How can I anchor a div Banner saying "Get 50% off our products" to the Navbar directly above it?

Bootstrap Question: How can I attach the div Banner ("50% off of our products") to the Navbar directly above it? The structure looks like this: <Navbar> </Navbar> <div> <span>Discount: 50% off of our products </span </di ...

React/Javascript - Executing Function returns prematurely

I have been working on a function that takes an object and iterates through it to create a search query. However, the issue I'm facing is that the function returns before I finish looping through the object: export default function buildQuery(query) ...

Looking to deactivate a particular checkbox in a chosen mode while expanding the tree branches

I encountered an issue with a checkbox tree view where I needed to disable the first two checkboxes in selected mode. While I was able to achieve this using the checked and readonly properties, I found that I could still uncheck the checkboxes, which is no ...

Redux saga will halt all other effects if one fails during execution

Having some trouble with yield all in saga effect, I've included a snippet of my code below function* fetchData(item) { try { const data = yield call(request, url); yield put(fetchDataSuccess(data)); } catch (error) { yield put(fetchDa ...

Ways to position an image in the middle of a Div

I am currently working with PHP and Smarty, attempting to display a slideshow's images in the center of a specific div, but I am encountering difficulties achieving this. Below you will find the code snippet. Can anyone help me figure out what I migh ...