Ensuring the footer stays at the bottom of the page using Tailwindcss and ReactJS

I've read numerous articles and posts about achieving this, but none of the methods seem to be effective for me.

My goal is to have the footer stick to the bottom of the page when viewed on mobile devices. It displays correctly on larger screens, but on mobile, it tends to position itself in the middle of Component.js unless a fixed position is applied.

I've experimented with various solutions, but I'm finding it difficult to get it to remain fixed. Please take a look at the code below.

index.css

body {
  position: relative;
  
  margin: 0;
  min-height: 100vh;
  height: 100%;
  width: 100%;
  overflow: auto;
  
}

Footer

<div className='md:relative lg:relative grid grid-rows-1 md:grid-rows-1 lg:grid-rows-1 
        inset-x-0 md:inset-x-0 lg:inset-x-0 '>
      <footer className='bg-dark-grey fixed md:fixed lg:static 
      bottom-0 md:bottom-0 lg:bottom-0 
      flex justify-around mt-auto
      left:0
      '>
      <a className=' text-sm text-white p-0 md:p-0 lg:p-2 ml-2 md:mr-0 lg:mr-0'>© 2021 Health Service Executive</a>
      <a className='underline text-sm text-white p-0 md:p-0 lg:p-2 ml-2 md:mr-0 lg:mr-0'>HSELive - We're here to help</a>
      <a className='underline text-sm text-white p-0 md:p-0 lg:p-2 ml-2 md:mr-0 lg:mr-0'>Cookie statement</a>
      <a className='underline text-sm text-white p-0 md:p-0 lg:p-2 mr-2 md:mr-0 lg:mr-0'>Accessibility</a>
      <a className='underline text-sm text-white p-0 md:p-0 lg:p-2 ml-2 md:mr-0 lg:mr-0'>Privacy</a>
      <a className='underline text-sm text-white p-0 md:p-0 lg:p-2 ml-2 md:mr-0 lg:ml-0'>Disclaimer</a>
      </footer>
      </div>

component.js

<div className="min-h-screen relative md:relative lg:relative 
    z-0 backdrop-opacity-95 
    w-full md:w-full lg:w-full xl:w-full
    h-72 md:h-80 lg:h-96 lg:bg-bottom
    md:shrink-0
    ">
      <img className="h-80 md:h-72 lg:h-96" src="assets/vaccine-banner-flip.png" />
      <div className="absolute md:absolute lg:absolute top-12 md:top-16 
      lg:top-20 left-8 md:left-40 lg:left-48 ">
        <h1 className="text-3xl md:text-3xl lg:text-5xl font-bold ">Welcome to the HSE <br/>Data Protection Portal</h1>

        {/* cards for logins */}
        <div className="
        grid grid-cols-1 md:grid-cols-2  lg:flex justify-center 
        mt-96 md:mt-24 lg:mt-32 
        mb-32 md:mb-0 lg:mb-0">
          <div className="md:w-72 lg:w-80 h-72 md:h-66 lg:h-72">
            <section className="bg-dark-green h-16 w-72">
              <h2 className="text-white text-xl font-bold p-2">
                I have already created my secure profile
              </h2>
              <div className="bg-white  text-black container">
                <li className="text-lg-2 list-disc">
                  If you have already completed the registration process you can
                  login to your profile using your username and password
                </li>
                <button className="mt-10 bg-purple-hse text-white font-bold p-2 rounded-sm w-44 ml-10 ">
                  Login
                </button>
              </div>
            </section>
          </div>

Answer №1

To place the footer at the bottom of the page, add the class fixed bottom-0 within the containing div (not on the footer tag itself).


<div className='.... fixed bootom-0'>
      <footer className='...'>
       .
       .
      </footer>
</div>

Refer to the example below for clarification:

<script src="https://cdn.tailwindcss.com"></script>

<div class="relative flex min-h-screen flex-col justify-center space-y-5 overflow-hidden bg-gray-50 py-6 sm:py-12">
  <!-- card1 -->
  <div class="relative bg-white px-6 pt-10 pb-8 shadow-xl ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-lg sm:rounded-lg sm:px-10">
    <div class="mx-auto max-w-md">
      <img src="/img/logo.svg" class="h-6" alt="Tailwind Play" />
      <div class="divide-y divide-gray-300/50">
        <div class="space-y-6 py-8 text-base leading-7 text-gray-600">
          <p>An advanced online playground for Tailwind CSS, including support for things like:</p>
          <ul class="space-y-4">
            <li class="flex items-center">
              <svg class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="11" />
                <path d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9" fill="none" />
              </svg>
              <p class="ml-4">
                Customizing your
                <code class="text-sm font-bold text-gray-900">tailwind.config.js</code> file
              </p>
            </li>
            <li class="flex items-center">
              <svg class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="11" />
                <path d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9" fill="none" />
              </svg>
              <p class="ml-4">
                Extracting classes with
                <code class="text-sm font-bold text-gray-900">@apply</code>
              </p>
            </li>
            <li class="flex items-center">
              <svg class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="11" />
                <path d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9" fill="none" />
              </svg>
              <p class="ml-4">Code completion with instant preview</p>
            </li>
          </ul>
          <p>Perfect for learning how the framework works, prototyping a new idea, or creating a demo to share online.</p>
        </div>
        <div class="pt-8 text-base font-semibold leading-7">
          <p class="text-gray-900">Want to dig deeper into Tailwind?</p>
          <p>
            <a href="https://tailwindcss.com/docs" class="text-sky-500 hover:text-sky-600">Read the docs &rarr;</a>
          </p>
        </div>
      </div>
    </div>
  </div>
  <!-- card 2 -->
  <div class="relative bg-white px-6 pt-10 pb-8 shadow-xl ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-lg sm:rounded-lg sm:px-10">
    <div class="mx-auto max-w-md">
      <img src="/img/logo.svg" class="h-6" alt="Tailwind Play" />
      <div class="divide-y divide-gray-300/50">
        <div class="space-y-6 py-8 text-base leading-7 text-gray-600">
          <p>An advanced online playground for Tailwind CSS, including support for things like:</p>
          <ul class="space-y-4">
            <li class="flex items-center">
              <svg class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="11" />
                <path d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9" fill="none" />
              </svg>
              <p class="ml-4">
                Customizing your
                <code class="text-sm font-bold text-gray-900">tailwind.config.js</code> file
              </p>
            </li>
            <li class="flex items-center">
              <svg class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="11" />
                <path d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9" fill="none" />
              </svg>
              <p class="ml-4">
                Extracting classes with
                <code class="text-sm font-bold text-gray-900">@apply</code>
              </p>
            </li>
            <li class="flex items-center">
              <svg class="h-6 w-6 flex-none fill-sky-100 stroke-sky-500 stroke-2" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="12" cy="12" r="11" />
                <path d="m8 13 2.165 2.165a1 1 0 0 0 1.521-.126L16 9" fill="none" />
              </svg>
              <p class="ml-4">Code completion with instant preview</p>
            </li>
          </ul>
          <p>Perfect for learning how the framework works, prototyping a new idea, or creating a demo to share online.</p>
        </div>
        <div class="pt-8 text-base font-semibold leading-7">
          <p class="text-gray-900">Want to dig deeper into Tailwind?</p>
          <p>
            <a href="https://tailwindcss.com/docs" class="text-sky-500 hover:text-sky-600">Read the docs &rarr;</a>
          </p>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- Footer -->
<div class="fixed bottom-0 h-16 w-full text-lg bg-blue-900 px-4 py-6 z-10 text-white">Footer @ Footer.com -2022</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

Managing JSON Data Objects in React

Trying to extract data from a parsed and stored JSON object in the state, but having trouble finding a solution. I've attempted various methods, however, I keep encountering errors (data is from OpenWeatherMap). class App extends Component { constr ...

Encountering a CSS issue during the edit process with PHP and JavaScript

I'm encountering an issue when clicking on the edit button, as my data fetched from the DB should be displayed inside a text field. However, I'm facing a CSS-related error: Uncaught TypeError: Cannot read property 'style' of null Belo ...

Revamping CSS for a Responsive Wordpress Tesseract Theme

I'm currently in the process of developing a website using the Tesseract theme at thevandreasproject.com. However, I have encountered an issue with responsiveness when integrating the SiteOrigins PageBuilder plugin. The compatibility between PageBuild ...

Guide on customizing Pagination Item within Pagination component in Material-UI and ReactJS

Seeking Advice Hello friends! I have a query regarding styling child components when importing only the parent component from material-ui. The Issue I want to customize the class of Pagination Item imported from Material-UI. Essentially, I am only imp ...

How to add suspense and implement lazy loading for a modal using Material-UI

Currently, I am implementing <Suspense /> and lazy() to enhance the performance of my project. While everything seems to be working smoothly, I have observed some minor changes in DOM handling that are causing me slight confusion. Consider this scen ...

A grid layout in Material UI with less than 12 columns

For my grid layout, I am looking to create columns that are separate into 10 instead of the standard 12. While I have been able to find information on increasing the number of default columns online, decreasing them has proven to be a challenge. Is it not ...

The span is unresponsive

When focusing on an input or checking its validity, the span should move up but it's not responding to any styles. <div class="login"> <span class="logtxt">Username or email</span> <input type=& ...

Learn how to use ReactJS with our comprehensive tutorial, which guides you through avoiding the common issue

Hey there! I recently started learning ReactJS and have been following this amazing tutorial: https://reactjs.org/tutorial/tutorial.html. So far, everything has been going smoothly except for one hiccup I encountered at this particular step: https://reactj ...

Despite utilizing the .img-fluid class, the image remains incompatible with the parent div and does not fit properly

So, I'm currently working on a test code where my aim is to fit an image into the parent div using Bootstrap 5. However, I'm facing a challenge where the image leaves a noticeable gap width-wise, despite using the .img-fluid class. You can see th ...

What is the best way to manage photos from your phone without having to upload them online?

I'm currently developing an application using AngularJS/Javascript, HTML, and CSS within a cloud-based environment on c9.io. My next task is to create and test an app that can access the phone's photo album, apply filters to images, and I'm ...

Is there a way to save four input values into an array of options?

I am trying to develop a polling feature using React, but I am encountering some issues with my code. In my React code, I have 4 input fields - option1, option2, option3, and option4. However, I am struggling to store data in the same way I do using POSTMA ...

Achieving Full Height for Parallel Columns Divs with Bootstrap - A How-To Guide

I am struggling with getting two divs in parallel to have full height. Even though I have the divs side by side, when I try to set their height:100%;, nothing happens. What CSS properties do I need to modify to achieve this? The goal is to create a cove ...

What steps can I take to address the div issue in my React application?

After implementing Browser Router, I am encountering whitespace on the left and right side of the navbar. How can I resolve this issue? Below is the code snippet: <div className="container my-3"> <BrowserRouter> ...

Changes to the parent state will not be reflected in the child props

When the child component PlaylistSpotify updates the state localPlaylist of its parent, I encounter an issue where the props in PlaylistSpotify do not update with the new results. I've been struggling to figure out what I'm missing or doing wrong ...

Align Text with Icon Using FontAwesome

Hey, I'm having a bit of trouble with something simple and it's driving me crazy. All I want to do is center the text vertically next to a FontAwesome icon. However, no matter what I try, I just can't seem to get it to work. I've looke ...

The iPhone header position switches when an HTML5 input type number is selected

I am currently working on a project that involves jQuery Mobile and PhoneGap. One issue I am encountering is when using the iPhone version, the header position changes when I click on an input type number. NOTE: When I focus on the input type number in my ...

"Enhanced visuals with parallax scrolling feature implemented on various sections for an engaging

With 4 sections, each featuring a background image and text in the middle, I encountered an issue when attempting to have them fixed while scrolling. The goal was for the section below the first one to overlap the one above it along with its text as we scr ...

Executing a single command to simultaneously run both node server.js and npm start can streamline your development workflow

Recently, I set up a fresh create-react-app with an Express backend on my local machine. Currently, I find myself having to start the server by running node server.js and then starting the frontend using npm start separately in order to ensure both compone ...

Unique Fragments with AstroJS

Recently delving into learning AstroJS, I stumbled upon some intriguing templates on GitHub. One thing that caught my attention was the <Fragment> tag which seemed to be related to directives based on the astro documentation. Below is a snippet of th ...

Resetting Material UI Checkbox upon closing a DialogWould you like to learn how

One of the challenges I encountered was creating a Dialog component using Material UI, which I dynamically imported from another file. Everything seemed to be working fine, except for the checkboxes (also built with Material UI) inside this Dialog not rese ...