0

I have seen a lot of articles and posts on how to achieve this but none of them are working for me.

What I want is for my footer to stay at the bottom of the page when viewing on mobile. It's fine on larger screens. On a mobile, unless position fixed is applied, it will place itself in the middle of Component.js.

I have tried a lot of different things and I'm struggling to get it to stick. Please view 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>
someone
  • 661
  • 1
  • 9
  • 26
  • Here you can see a lot of method on how to achieve this [in here](https://stackoverflow.com/questions/643879/css-to-make-html-page-footer-stay-at-bottom-of-the-page-with-a-minimum-height-b). Do the exact same thing but with your tailwind classes. – maiakd Apr 21 '22 at 14:55
  • this is not helpful. I have read this before. – someone Apr 21 '22 at 15:01
  • Well, I can't help you like that. Between your semantic errors (`li` but no `ul`, unnecessary `div`around `section` and `footer`, no `alt` on `img`), you'll need to clean that out sooner or later, and the unnecessary repeating classes such as `absolute md:absolute lg:absolute` you should [Read this: Tailwind Mobile First](https://tailwindcss.com/docs/responsive-design) and Read more about the DRY Method (Don't Repeat Yourself) there are a lot of great articles out there. – maiakd Apr 22 '22 at 07:58
  • Now, the code you've shared isn't near ENOUGH. I need to see the full indentation to understand why the above solution doesn't work where it should. Can you please copy and paste (in the edit of this post) the HTML output from the inspector of your navigator ? I don't need all the source code, just the whole `` and if you have custom `.css` add them too, thanks. – maiakd Apr 22 '22 at 08:03

1 Answers1

0

Just add the class fixed bottom-0 in the div containing the footer.(Not on the footer tag like you have done).


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

I had attached an example below, just ignore the cards and see the footer only,

<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>
MagnusEffect
  • 3,363
  • 1
  • 16
  • 41