I attempted to make a footer stick to the bottom of the page, but unfortunately, it does not seem to

This is a preview of my page:

https://i.sstatic.net/7uLH9.png

I attempted to apply position: relative to my PageContainer but the footer remains in place. How can I resolve this issue?

Below is the code from App.js:

const PageContainer = styled.div`
  position: relative;
`;

function App() {
  return (
    <>
      <GlobalStyle />
      <PageContainer>
        <TopNav />
        <SideNav />
        <RouterStyle>
          <Router>
            <ContactForm path="/contact" />
            <ShopAllProducts path="/" />
            <NewArrival path="/shop/new-arrival" />
            <Product path="/product/:title_url" />
          </Router>
        </RouterStyle>
      </PageContainer>
      <Footer />
    </>
  );
}

Here is the code for Footer.js:

const FooterWrapper = styled.div`
  padding: 10px 0;
  font-family: ${fonts.Gotham};
  font-size: ${fontSizes.sm};
  font-weight: 500;
  position: absolute;
  bottom: 0;
  background-color: red;
  width: 100%;
`;

const FooterContainer = styled.div`
  justify-content: space-between;
  display: flex;
`;


const Footer = (props) => {
  return (
    <FooterWrapper>
      <FooterContainer>
        <LinkFooter to="/">Privacy & Policy</LinkFooter>
        <Beuter2020>© 2020 THE BEUTER</Beuter2020>
        <LinkFooter to="/">Facebook</LinkFooter>
      </FooterContainer>
    </FooterWrapper>
  );
};

P.S.: I am utilizing styled-components for styling

After removing position: absolute, bottom:0 https://i.sstatic.net/NUDEq.png

You can check out the project on Github: https://github.com/nathannewyen/the-beuter

Answer №1

If you change the position from absolute to fixed, it will prevent the footer from scrolling along with the page content.

Ensure that the footer is within the root element to avoid inheriting parent styles like padding. Be clear in your CSS declarations to address this issue.

left: 0;
right: 0;
bottom: 0;

The problem lies in the positioning of the footer, not the styling.

To fix this, use the following code:

.footer{
padding: 10px 0;
font-weight: 500;
left: 0;
right: 0;
bottom: 0;
position: fixed;
background-color: red;
width: 100%;
}
<div>
Content here
</div>

<div class="footer">
Footer content
</div>

You don't need a sticky footer if the main element occupies the full height (100vh) and pushes the footer down automatically.

.main{
min-height: 100vh;
width: 100%;
}
.footer{
background: red;
height: 20px;
}
<div class="main">
Main content
</div>

<div class="footer">Footer</div>

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

Styling dropdown menus with CSS

I have encountered an issue with the dropdownlist control on my asp.net page. I set the width to 150px, but in Mozilla browser, the list items appear expanded while in IE, they are restricted to the width of the dropdown list. How can I achieve a consisten ...

Rotate the image as you hover your cursor over it

I am trying to implement a script where the image is rotated when the user hovers over it. Unfortunately, the hovering effect is not functioning as expected. $("#alcazar-image").rotate({ bind: { mouseover : function() { $(this).rotate({anima ...

Activate each division separately with a single script

I am facing an issue where each blue div (<div id="rectangle"></div>) is not firing independently when hovered or clicked. Currently, when I hover/click over the first one, both fire simultaneously. However, if I hover/click over the second on ...

What steps can you take to convert your current menu into a responsive design?

I am currently developing a website using PHP, HTML, and CSS. The site is not responsive, and I want to make the menu responsive. My global navigation and admin interface are not adapting properly as they are designed using tables. Is there a method I can ...

Steps for eliminating a selection in the dropdown list:

I am dealing with a situation in which my select element gets new options added based on a specific input value. However, each time the value is changed, more options are appended to the select element instead of replacing the old ones. How can I remove th ...

Error: NextJS Client-Side Rendering Issue

I find this situation quite perplexing... Everything seems to be working fine except for the onClick code and useEffect code. I attempted running document.querySelector('button'); in the console, but it returned undefined. It appears that JavaSc ...

The state of the React-redux application is initialized prior to the component being rendered

Is there a way for my component to receive notifications of the redux state when it mounts? Even though I set up mapStateToProps to be notified of state changes, it seems that the change occurs before the component is created, resulting in no notificatio ...

Can you explain the distinctions among the accessible, accessibilityLabel, and accessibilityHint properties of the Text component in React Native?

Can you explain the distinctions among the accessible, accessibilityLabel, and accessibilityHint properties of the Text component in react native? The information provided in the React Native documentation is insufficient. It would be helpful to see some ...

How can I insert a item into an Array using JavaScript code?

My instructor set up an array in my JavaScript file that is off limits for me to modify. My task is to add new objects to it through code without directly manipulating the existing array. Here's a snapshot of what my array contains: const words = [{ ...

"Guidelines for implementing a post-login redirection to the homepage in React with the latest version of react-router (v

I am facing an issue where I am unable to redirect to the Home Page when I click the "Login" button during my React studies. Despite trying all possible methods for redirects, none of them seem to work. The function that is executed when I click the "logi ...

Leveraging React hooks within a third-party API service integration layer

I'm currently developing a react application for an online store that focuses on eCommerce. One of the main pages I'm working on is the Product Search page. To handle data fetching and caching efficiently, I decided to utilize the SWR library by ...

Switch up the port in a React application using VITE

Currently, I am developing an application that combines Laravel 10 with React JS and Vite. In order to change the port, I updated it in the package.json file within the "dev" script section like this ("dev": "vite --port=3000"). However, despite making thi ...

Utilizing the power of React Final Form in combination with the efficient react-places

I've done my research on similar questions, but they all remain unanswered! Currently, I have set up a standard record-level like the one shown here: Using React Final Form with react-places-autocomplete, I aim to incorporate the selections made in ...

Enhancing HTML "range" element with mouse scroll functionality for incrementing values in step increments

I'm working on developing a scroll feature that operates independently from the main window's scrolling function. I aim to trigger specific events in the primary window based on interactions with this separate scrollbar. The only solution I coul ...

ChessboardJs: JavaScript Boards Function Properly on Initial Use Only

Update: The page code can be accessed via my page URL. I'm unsure where the issue lies. Your assistance is appreciated. Issue: Initially, when clicking on the chess puzzles page, everything works fine. However, upon re-clicking from the homepage, th ...

Unable to locate the Bootstrap CSS file when deploying on PythonAnywhere

I recently created an admin panel that integrates with a database. To automate the process of generating the admin panel, I utilized flask-admin. Running the server locally on my PC displayed the bootstrap swatch correctly and everything worked seamlessly. ...

The JSX component cannot utilize 'Home' when working with React and TypeScript

I am a beginner in using React and TypeScript, and I want to retrieve data from an API and display it in a table using TypeScript and React. My project consists of two files: Home.tsx and App.tsx. The primary code that interacts with the API is located in ...

I am attempting to utilize a ref in React to access an element within a MUI modal, but I am encountering issues as the reference to the

I've been encountering an issue while trying to access the component did mount lifecycle method, as it's showing null. Interestingly, when I remove the modal, everything works as expected. However, inside the modal, the ref isn't functioning ...

Testing the Limits of CSS Hover

I'm having trouble figuring out how to implement this. When hovering, a yellow square/background should appear with an offset similar to the one in the image below. I am utilizing bootstrap for this project. Any assistance or guidance would be greatl ...

The menu item is having trouble aligning to the right side

Hello, I am currently working on developing a website menu for a project and I am facing an issue with aligning the "Login" Menu item to the right side. Any assistance in resolving this alignment issue would be greatly appreciated. I am also willing to pro ...