Ways to create a fixed button positioned statically at the bottom of a page

Currently, I am utilizing tailwind CSS to create a webpage with Next and Back buttons for navigation. However, an issue arises when there is minimal content on the page as the button adheres to the top. For visual reference, please view the image linked below.

Image link:- https://ibb.co/pw5QN2N

The code snippet used for these Buttons is as follows:

<div className="flex justify-between">
            <NavLink to={"/course/" + courseName + "/" + (+moduleID - 1)}>
              <button
                      className="my-8 float-right px-5 py-2 bg-red-500 text-white text-sm font-bold tracking-wide rounded-full focus:outline-none"
                    >
                      Back
                </button>
            </NavLink>
            {courseContent[courseName][+moduleID - 1].quiz === true ? (
              <NavLink to={"/course/" + courseName + "/" + +moduleID + "/quiz"}>
                <button
                      className="my-8 float-right px-5 py-2 bg-red-500 text-white text-sm font-bold tracking-wide rounded-full focus:outline-none"
                    >
                      Next (Quiz)
                </button>
              </NavLink>
            ) : (
              <NavLink to={"/course/" + courseName + "/" + (+moduleID + 1)}>
                <button
                      className="my-8 float-right px-5 py-2 bg-red-500 text-white text-sm font-bold tracking-wide rounded-full focus:outline-none"
                    >
                      Next
                </button>
              </NavLink>
            )}
            </div>

I am seeking advice on how to rectify this issue so that the button remains fixed at the bottom of the page.

Answer №1

Enclose those buttons within a <div> element and assign the classes fixed bottom-0 w-full to that <div> element.

For example:

<div class='fixed bottom-0 w-full'>
    <button class='my-8 float-right px-5 py-2 bg-red-500 text-white text-sm font-bold tracking-wide rounded-full focus:outline-none'>Back</button>
    <button class='my-8 ml-auto px-5 py-2 bg-red-500 text-white text-sm font-bold tracking-wide rounded-full focus:outline-none'>Next(Quiz)</button>
    <button class='bottom-0 my-8 float-right px-5 py-2 bg-red-500 text-white text-sm font-bold tracking-wide rounded-full focus:outline-none'>Next</button>
</div>
  • w-full sets the width to 100%
  • fixed positions the element as fixed
  • bottom-0 aligns the element to the bottom of its container

Answer №2

apply the following style to the main container div

{
  position: absolute;
  top: 100%
}

Answer №3

<link href="https://unpkg.com//<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3642575f5a415f58d55554555446514">[email protected]</a>/dist/tailwind.min.css" rel="stylesheet" />

<div class="flex flex-col justify-between min-h-screen p-5">
  <div>
    <h1 class="text-3xl font-bold">Network Security</h1>
    <h1 class="mt-5 text-2xl font-medium text-blue-500">Essential Concepts</h1>
    <p>Exploring the basics of network security...</p>
  </div>

  <div class="flex justify-between">
    <button class="px-5 py-2 text-sm font-bold tracking-wide text-white bg-red-500 rounded-full focus:outline-none">Previous</button>
    <button class="px-5 py-2 text-sm font-bold tracking-wide text-white bg-red-500 rounded-full focus:outline-none">Continue</button>
  </div>
</div>

https://play.tailwindcss.com/WY4qZvba15

Answer №4

If you're looking to keep your buttons fixed at the bottom of the page, regardless of the content above them, here's a solution for you. This code will ensure that the buttons stay pinned to the bottom while allowing you to customize their styling individually, such as their position, color, etc.

.b {
  position: absolute;
  bottom: 10px;
}

.next {
  right: 50px;
}

.back {
  left: 50px;
}
<div>
<!--  you can still have your container -->
<div>content up here, buttons below</div>
<!-- you can still have your content -->
<button class="b next">next</button>
<!-- and your buttons will stick to the bottom -->
<button class="b back">back</button>
</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

Plugin for webpack that replaces a specified function with an alternative one

I'm currently working on a webpack plugin that has the ability to analyze code and replace a particular function with another function. Additionally, this plugin will make the new function accessible globally. class PluginName { constructor(local, ...

What is the best way to alter the background of a div when hovering over an image?

I am looking to achieve a unique effect with my thumbnail image and background. Currently, I have the thumbnail image inside a div with another image serving as the background to frame it. My goal is to change the position of the background image from bott ...

Struggling to obtain the Variable

Trying to send a POST request to my ESP8266 HTTP Server, I need to transmit 4 variables: onhour, offhour, onminute, offminute. These variables should be retrieved from a timepicker-component imported from "ng-bootstrap" Despite numerous attempts over the ...

What is the best way to retrieve form values on the server in nextJs?

I'm facing an issue with passing form data to my API endpoint in nextJS. I have set up the form using Formik and Yup for validation. Oddly, when I check the console on the client side, I can see the user input values just fine, but on the server side, ...

Exploring Tabletop.js to retrieve information from an array of data

Issue I am currently attempting to retrieve data from an array that contains two objects. I have implemented Tabletop.js to fetch the data from a public Google Spreadsheet, but I encountered an error in the console stating ReferenceError: object is not de ...

Tips for stopping PHP echo from cutting off a JS string?

I encountered an issue with my code: <!DOCTYPE html> <html> <head> <title>Sign up page</title> <meta charset="UTF-8"/> </head> <body> <h1>Sign up page</h ...

Tips for triggering window load event on a particular page

I need to trigger the windows.load event on a specific page. Currently, I have set it up like this: $(window).load(function(){ if(document.URL == "/car-driving.html") { overlay.show(); overlay.appendTo(document.body); $('.popup' ...

Determine whether the browser tab is currently active or if the user has switched to a different

Is there a way to detect when a user switches to another browser tab? This is what I currently have implemented: $(window).on("blur focus", function (e) { var prevType = $(this).data("prevType"); if (prevType != e.type) { // handle double fir ...

What are the steps to add 8 columns to the second row in my table?

this is an example of HTML code that showcases a table structure with multiple rows and columns. You can view the full code snippet here. The table includes different sections, such as section1, section2, section3, and section4 in the first row (tr). In t ...

How can you receive a file through AJAX response?

I have a standard Ajax function that I regularly use to call a specific function within my node.js server. This particular function is responsible for retrieving a file (usually in xls format) from the server and streaming it back to the client. Below is ...

What are the steps to implement an audio stream in a JavaScript React application?

I have been working on integrating a web dialer system into my JavaScript NextUI React app. After making some progress, I can successfully dial and hear my voice through the phone. However, I am encountering an issue where I cannot hear the other person sp ...

Discovering an HTML Element in a JavaScript Array with Specific Styling: A Step-by-Step Guide

I am in the process of developing a website that consists of different sections. The concept is simple - by clicking on a button located at the bottom of the page, it will reveal the corresponding div section. For styling purposes, I have initially hidden ...

Automatically tapping the Quora "expand" button through code

I am attempting to automate the clicking of the "more" button located at the bottom of a page like using watir. Below is the code I currently have: require 'watir-webdriver' b = Watir::Browser.new b.goto 'quora.com/'+ ARGV[2] + ' ...

What are the steps to create a "gooey glide" animation using React and MUI?

I am looking to create a unique animation for my list of items on a web page. My goal is to have the items slide in one by one with rapid succession and then slightly shrink once they reach their final position, similar to how pillows might fall or like a ...

Unable to determine the data type of the JSON object during the

I'm having trouble reading an Object type of json... Here is the json I'm working with: body: { "111": { "name": "name1", "status": 10000 }, "222": { "name": "name2", "status": 20000 }, "333": ...

Running a code from a plugin in Wordpress site

I am currently utilizing the "wp-video-lightbox" plugin for WordPress, which generates small floating boxes for my videos. I am interested in incorporating variables like http://www.example.com/?video3 to provide shortcuts similar to what YouTube offers. ...

The ssh2 module experiences a quiet failure when provided with credentials that are successful when used from

After successfully connecting to Google Cloud Compute using the CLI with a command like this: ssh -i ~/.ssh/my-ssh-key me@ipnumber I have encountered a problem where the ssh2 module is not providing any output or errors. var fs = require('fs') ...

React with Typescript allows us to refine the callback type depending on the presence of an optional boolean prop

In my project, there's a component <Selector /> that can optionally accept a parameter called isMulti: boolean. It also requires another parameter called onSelected, whose signature needs to change depending on the value of isMulti (whether it i ...

Modify the value of mat-slide-toggle from TypeScript code

This is the HTML code I have for a mat-slide-toggle element, with a toggleStatus() function: <span class="form-control form-control-plaintext"> <mat-slide-toggle name="status" checked="" ...

Issue arises when compiling React Redux due to a union type that includes undefined

I am currently in the process of learning how to integrate Redux with React using Typescript. I encountered a compilation error that relates to the type of my store's state, specifically as {posts: PostType[]}. The error message states: Type '{ p ...