React Issue: Footer not staying attached at the bottom of the page

I'm currently developing a website with react, but I'm struggling to keep the footer at the bottom. When there isn't enough content, the footer ends up right after the content instead of staying at the bottom. I've tried various solutions, but I believe there might be an issue with the overall structure.

Below is the code I'm working with:

App.css:

.App {
  text-align: center;
}

body{
    min-height: 50%;
    display: flex;
    flex-direction: column;
}
footer.footer{
    margin-top: auto;
    bottom: 0;
    margin-bottom: 0;
}
.App-logo {
  height: 40vmin;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .App-logo {
    animation: App-logo-spin infinite 20s linear;
  }
}

.App-header {
  background-color: #282c34;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
}

.App-link {
  color: #61dafb;
}

@keyframes App-logo-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

Footer.js:

import React from "react";
import './Footer.css';
import {GrGithub, GrInstagram, GrLinkedin, GrTwitter} from 'react-icons/gr';

export const Footer = () =>{
    return (
        <footer className="footer">
            <p>2022 &copy; All right Reserved <br/> Khaled Nadam</p>
            <ul className="footer-social">
                        <li><GrInstagram /></li>
                        <li><GrLinkedin /></li>
                        <li><GrGithub /></li>
                        <li><GrTwitter /></li>                
                    </ul>
        </footer>
    );
}

Footer.css:

.footer{
    background-color: #1C4B82;
    color: #DAE1E7;
    width: 100%;
}
.footer p{
    padding: 20px 0;
    font-size: .8rem;
    text-align: center;
}
.footer .footer-social{
    margin:auto;
    text-align: center;
    list-style: none;
    display: inline-flex;
    padding-right: 40px;
}
.footer .footer-social li{
    padding: 10px 20px;
}

Appreciate any help in advance.

Answer №1

The reason why it's not working for you is because the position property in your CSS is missing.

You can test the following code:

body {
  position: relative;
} 

.footer {
  position: absolute;
  bottom: 0;
  left: 0;
}

Answer №2

Make sure to include position: absolute in the CSS for the footer section.

.footer{
    position:absolute;
    bottom:0;
    left:0;
    }

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 retrieve all the listed TV and film ratings in descending order? Using Django

Our Goal I aim to organize movies based on their star ratings and filter out those with ratings lower than a specified threshold. 2. Retrieve the IDs of Movies and TV shows mentioned in the view, fetch the data and score through URLs one by one. 3. Presen ...

Develop a responsive component on the right side

I am encountering an issue with creating a responsive div that matches the height of the image on the left side. I want to include text in this div, however, when I do so, the paragraph expands in height along with the div element when I attempt to change ...

Error encountered in Pokemon API: Trying to access property '0' of undefined

My current challenge involves accessing the abilities of my Pokemon, but I keep encountering a recurring error. In my project development using React hooks, I fetched data from the Pokemon API and stored it in setWildPokemon. Utilizing wildPokemon.name suc ...

Having trouble setting up a React 18 project with TypeScript and Redux Toolkit

I'm encountering an issue while setting up a project with the latest versions of React 18, TypeScript, and Redux Toolkit. Specifically, I'm facing a problem when trying to install '@reduxjs/toolkit', as it throws the following error: np ...

Even after shutting down my PeerConnection, the black screen persists. I would appreciate assistance in resolving this issue

Welcome to the Room.js Client Side Code! import React, { useEffect, useRef, useState } from "react"; import io from "socket.io-client"; import Peer from "simple-peer"; import styled from "styled-components"; const C ...

Add CSS styling to a single form

When working on a larger project, the goal is to reduce the size of various elements within a form named quickpost-form <div id="qp-form"> Specific elements in the form require a smaller font size such as text, input, input-group, and tex ...

JavaScript Function that Automatically Redirects User or Updates Text upon Clicking "Submit" Button

Looking to create JavaScript functionality that directs users back to the homepage after submitting their name and email. The process should follow these steps: 1.) User clicks "Request a Brochure..." https://i.sstatic.net/KqH2G.jpg 2.) A window opens in ...

Hiding a pop-up element and updating the state to False when clicking anywhere outside the element in the background

Presented here is my Search.js component. class Search extends Component { state = { doctors: [], showTab: false } openTab = () => { this.setState({showTab: true}); console.log('openTab state', this ...

What is the best way to extract and display data from an API response object in my

{ "_metadata": { "uid": "someuid" }, "reference": [ { "locale": "en-us", ... bunch of similar key:value "close_icon_size" ...

Embed SQL parameter into HTML code

Every 24 hours, I have a SQL job that sends an email containing data extracted from my database tables. I store the data in : DECLARE @ReportContentBuilder table(LineSequence int identity, Line varchar(2000)) Here's how it's done : INSERT IN ...

Tips for positioning a grid at the center of a MaterialUI layout

I am struggling to position 3 paper elements in the center of both the vertical and horizontal axes on the screen. Despite applying various CSS rules and properties, the height of the HTML element consistently shows as 76 pixels when inspected in the con ...

Having trouble calculating the number of days between two dates at this moment

I'm working with a code snippet that involves comparing two dates – a specified date and the current date. However, when trying to calculate the difference in days between these dates, I keep getting either 0 or an unexpectedly large number like "31 ...

What happens when there is a 1-second delay in loading CSS on an HTML page?

Lately, I've been working on creating HTML and CSS pages. However, whenever I load a page, I notice that there's always a brief half-second flash of the HTML content without any styling applied. Does anyone have an idea why this is happening and ...

In Safari, the scrollbar appears on top of any overlays, popups, and modals

On my webpage, I have a div with the CSS property overflow-y: scroll. The page also features several popup modals and overlays. Strangely, the scrollbar of the div appears on top of these overlays instead of behind them. I attempted to resolve this issue b ...

Unable to change Bootstrap variables within a Next.js project

I'm having trouble changing the primary color in Bootstrap within my NextJS project. I've tried different methods but nothing seems to work as expected. Here is the code snippet from my "globals.scss" file that I imported in "_app.js": $primary: ...

Unable to write to csv file in UTF-8 using PHP fwrite, experiencing issues

Looking for assistance with handling PHP fwrite as CSV file is displaying incorrect characters. The output appears like this: općšpšćšćšp ćpšćpšćp šćpšćpšć This is the PHP code being used fo ...

The values in my JavaScript don't correspond to the values in my CSS

Is it possible to retrieve the display value (display:none; or display:block;) of a div with the ID "navmenu" using JavaScript? I have encountered an issue where I can successfully read the style values when they are set within the same HTML file, but not ...

Preventing navbar resizing on websites

I'm trying to have a section on the navbar dedicated for text or alerts that appear based on certain events. However, even when the alert is hidden, it still affects the height of the navbar. How can I resolve this issue? It may be difficult to see i ...

Nested elements not transitioning using CSS

Why is my transition not being applied to the submenu <a> tag? The color change is working fine, but the transition does not occur on hover. When I use the same rules on another element with a different main class, it works perfectly. It seems like t ...

What is the best way to include a background image in a div within a React component?

I'm currently following a tutorial on creating an RPG game using React. The tutorial can be found at this link. I am trying to replicate the presenter's code by typing it out myself. However, I'm running into an issue when attempting to add ...