Why is the Footer component in Next.js Styling not staying at the bottom of the screen as intended?

Why is the Footer component not at the bottom of the screen in Next.js Styling?

import Head from "next/head";

import Navbar from "./Navbar";
import Footer from "./Footer";

const layoutStyle = {
  display: "flex",
  flexDirection: "column",
  height: "100%",
  width: "100%"
};

const Layout = props => (
  <div className="Layout" style={layoutStyle}>
    <Head>
      <title>Oracle</title>
      <meta name="viewport" content="width=device-width, initial-scale=1" />
      <meta charSet="utf-8" />
    </Head>
    <Navbar />
    <div>{props.children}</div>


    <Footer/>
  </div>

);

export default Layout;

footer

import React, { Component, Fragment } from "react";


class Footer extends Component {
    render() {
        return (
            <div className="bg-gray-100">
                <div className="bg-gray-100 container mx-auto px-6 pt-10 pb-6" >
                    >
                    © Oracle Corp. All rights reserved.
        </div>
            </div>
        )
    }
}

export default Footer;

This issue seems to be related to Next.js, but I'm unsure how to resolve it :/

I suspect it has something to do with how Next.js sets up each page.

Thank you for your help,

Answer №1

Experiment with changing the styling of the __next element enclosing the app.

#__next {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

Answer №2

After investigating further, I successfully replicated the issue and resolved it by adjusting the positioning of the footer to the bottom of the page. This was achieved by incorporating an inline style within the Footer component using

style={{ position: "absolute", bottom: 0, width:"100%" }}
. The updated component code is as follows:

import React, { Component, Fragment } from "react";

class Footer extends Component {
  render() {
    return (
      <div style={{ position: "absolute", bottom: 0, width:"100%" }} className="bg-gray-100">
        <div className="bg-gray-100 container mx-auto px-6 pt-10 pb-6">
          > © Oracle Corp. All rights reserved.
        </div>
      </div>
    );
  }
}

export default Footer;

Answer №3

const footer = (
  <div style={{ position: "absolute", bottom: 0, width:"100%" }} className="bg-gray-100">
    <div className="bg-gray-100 container mx-auto px-6 pt-10 pb-6">
      > © MegaCorp Ltd. All rights reserved.
    </div>
  </div>
);

It did the trick for me.

Answer №4

When working with Next.js, you can set a global style for the

<div class="container">
in the 'pages/_app.js' file.

        <style jsx global>
          {`

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

          `}
        </style>

Answer №5

For those who have organized their components within a src folder, it is important to update the Tailwind config file. Before:

  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],

After:

  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./src/components/**/*.{js,ts,jsx,tsx}",
  ],

This simple adjustment solved my issue!

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

Leverage the NextRouter functionality without the need for a React component

I've created a custom hook that checks if a user is logged in and redirects them to the login page if not. Below is a simplified version of the hook assuming the user is not logged in: import { useRouter } from 'next/router'; export default ...

How can divs be styled to mimic the behavior of tables in IE6 using just CSS and HTML?

Can div elements be styled to resemble tables in IE 6 using just CSS and HTML? Unfortunately, the display properties like table, table-row, or table-cell do not work in IE 6 If it is feasible, what strategies can be employed? ...

Leverage React components for efficient code reuse and export modules for

I have Project X, which was built using the command "yarn build" and it generated a main.js file. I am trying to use this main.js file as a dependency for another React project Y. Unfortunately, following the steps from React components and module exports ...

Authenticate users with JSON Web Tokens in a Next.js/React application while connecting to an AWS

I'm working on a Next.js application that interacts with AWS functions. I'm interested in incorporating a login feature using JWT tokens, but I am unsure of how to proceed. Since I plan to publish the app as a static website, I would prefer not t ...

The absence of dependencies in React's useEffect

I keep receiving a warning about missing dependencies in my useEffect, but I am hesitant to add them because it will cause the page to refresh whenever I alter the input values of these dependency fields. Currently, I have two state variables for my start ...

Assistance needed to identify CSS issue specifically in FireFox browser

Working on a new webpage and encountered an issue with the HTML markup: <!DOCTYPE html> <html lang="en> <head> <meta charset="utf-8"> <title>TileTabs</title> <link rel="stylesheet" href="css/style.css" t ...

What is the best way to design a basic server component that has the ability to retrieve data in NextJS 13?

Exploring the world of NextJS, I am currently utilizing NextJS 13 with the new app directory instead of the traditional pages directory structure. Despite trying various methods to fetch data, none seem to be working as expected. The process should be stra ...

Can you provide guidance on aligning text in a text area to the center?

I've been trying to align my "field labels" in the center of their respective text fields without much success so far. To achieve this, I resorted to using tables but that didn't quite do the trick. Currently, I'm experimenting with CSS prop ...

What could be causing my Reanimated (React Native) code to fail on Android devices?

Check out my React Native code using Reanimated and react-native-gesture-handler: import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, Dimensions } from 'react-n ...

error - ReferenceError: The function 'verifyUser' cannot be accessed before it has been initialized (No Circular Dependency)

Currently, I am implementing NEXT JS with Firebase and have set up Firebase-admin services as follows: import { initializeApp } from 'firebase-admin/app'; import { credential } from 'firebase-admin'; import { getAuth } from 'fireba ...

Update the color of navigation items to reflect their active status

Here is the snippet of HTML code: <header> <nav> <a href="#" id="menu-icon"></a> <ul> <li><a href="#"">Home</a></li> <li><a href="#">About</a></li> & ...

Is it possible to incorporate a CSS3 transition into the styling of a list of images?

Looking to achieve a CSS3 linear transition for a "list-style-image" specifically for Firefox? You'll need to include "-moz-" in your code. -moz-transition: list-style-image 0.2s linear; However, the above code is not producing the desired result. I ...

Maintain the flow of a floated or absolutely positioned element using CSS

Is there a way in CSS to ensure that floated or absolutely positioned elements remain within the flow? I find it frustrating that CSS lacks something like flow:on and flow:off to control this. The main issue I am facing is with having a div element of var ...

What is the best way to maintain the current position in a component while interacting with another component?

I have a component that displays a collection of cards with images. There is a button that toggles between showing another component and returning to the original list of cards. The issue I am encountering is that every time I return to the list of cards, ...

Vertically center text in an email within a div using HTML

i'm struggling to perfectly center the text within a div in an HTML email. While it appears fine in Browserview with proper line-height, issues arise in Apple Mail and Outlook where it doesn't align vertically. <div style='width: 80%; ...

Animated CSS sidemenu (utilized as a filtering panel for a table)

Hi there, I'm having some trouble with CSS Animation. I recently started developing websites and am using Bootstrap 4 along with Animate.css for animations. My goal is to have an icon button expand sideways to reveal a div containing select elements f ...

Issue with Material UI and React Autocomplete: Popover does not properly display when an item is selected, causing Autocomplete to

I'm currently working on a customized Autocomplete feature, where each item displays a more icon when hovered over with a mouse pointer. The issue I am facing is that instead of triggering a Popover when clicking the icon, it closes the Autocomplete ...

Encountering an isObject issue while using the @material/core package

When attempting to run the project, I encountered this error in the console: isobject error Upon inspecting the package-lock.json file, I discovered that the isobject dependency was missing in @material-ui/core. Adding it manually resolved the issue. pac ...

Navigating with React Router Dom and parsing objects in search parameters

Currently, I am utilizing React Router Dom v6 and require the ability to retain object search parameters within the URL. My current approach involves: const [searchParams, setSearchParams] = useSearchParams(); const allSearchParams = useMemo(() => { ...

What is the best way to adjust the scroll speed within a specific element using React?

Hey there, I'm currently working on adjusting the scroll animation of a div (MUI Container) to make it smoother and slower. I've spent some time searching online for a solution but haven't found anything helpful so far... By the way, I' ...