The fixed position setting does not anchor the elements to the bottom of a container

When applying the following styles:

#fullpage-menu > .gradient {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0.3rem;
}

To the element with ID #fullpage-menu, which is styled as follows:

#fullpage-menu {
    height: 100%;
    width: 100%;
    background-color: var(--secondary-button-color);
    left: 0;
    position: absolute;
    top: 0;
    animation: expand-fullpage-menu 500ms cubic-bezier(0.42, 0, 0.07, 1.43);
    z-index: 1001;
    animation-fill-mode: both;
    padding: 1rem;
    box-sizing: border-box;
    overflow: hidden;
    transform: translate(-100%);
    overflow-y: auto;
}

and

.apply-for-org .apply-button {
    background-color: var(--dark-secondary-button-color);
    padding: 0.5rem 1rem;
    border-radius: 10rem;
    border: none;
    cursor: pointer;
    color: var(--title-color);
    transition: all 300ms ease-out;
    user-select: none;
    display: block;
    clear: left;
    font-size: 1.3rem;
    text-transform: capitalize;
    font-family: bahnschrift;
    letter-spacing: 0.05em;
    margin: 1rem 0 0 1rem;
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translate(-50%);
    font-weight: lighter;
}

The selector .gradient should be visible at the bottom of each fullscreen menu, while the .apply-button should appear at the bottom of the .apply-for-org container, which also has the ID #fullpage-menu.

In essence, this setup means that the gradient bar in the .apply-for-org menu should remain anchored to the bottom even when scrolling through content exceeding the screen's height.

If implemented, the corresponding HTML structure for a fullpage-menu would look like this:

<div id="fullpage-menu" class="apply-for-org">
  
  <!--Content and other cool stuff-->

  <button class="apply-button">Apply for Organisation</button>
  <div class="gradient"></div>
</div>

Yet there seems to be an issue – why do the gradient bar and apply button not stay fixed at the bottom of the screen when scrolling within the content?

https://i.stack.imgur.com/5SDOB.png

https://i.stack.imgur.com/6Gfqx.png

EDIT 15/04/2021:

#fullpage-menu {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: #121a21;
  overflow-y: auto;
}

#fullpage-menu > button.close {
  padding: 0.5rem 1rem;
  position: absolute;
  top: 1rem;
  right: 1rem;
  border-radius: 10rem;
  font-family: bahnschrift;
  background-color: #070b0e;
  border: none;
  color: white;
}

#fullpage-menu .gradient {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0.2rem;
  background: rgb(131,58,180);
  background: linear-gradient(41deg, rgba(131,58,180,1) 0%, rgba(181,73,227,1) 28%, rgba(253,29,29,1)     83%,   rgba(252,145,69,1) 100%);
}

.apply-for-org .apply-button {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translate(-50%);
  background-color: #070b0e;
  border-radius: 10rem;
  border: none;
  color: white;
  padding: 0.5rem 1rem;
  font-family: bahnschrift;
  cursor: pointer;
}

/*Specific styling for this scenario*/
#example-content {
  height: 100rem;
  width: 70%;
  margin: auto;
  background: rgb(238,174,202);
  background: radial-gradient(circle, rgba(238,174,202,1) 0%, rgba(148,187,233,1) 100%);
}
<div id="fullpage-menu" class="apply-for-org">
<button class="close">Close</button>

<div id="example-content"></div>

<button class="apply-button">Apply for Organisation</button>
<div class="gradient"></div>
</div>

The code snippet appears functional, but unfortunately doesn't seem to work as expected on my locally hosted server...

On a side note, I am utilizing .ejs instead of .html, though this detail shouldn’t play a significant role (I assume).

Answer №1

If you encounter a similar issue in the future, simply resolve it by enclosing all content within another div with the position:block attribute:

<div id="fullpage-menu" class="apply-for-org">
  <div class="main-wrapper">
    <!--All fancy content goes here-->

    <div class="gradient"></div>
    <button class="apply-button">Apply for Organisation</button>
  </div>
</div>

To ensure functionality, apply these styles:

#fullpage-menu {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: #121a21;
  overflow-y: auto;
}

#fullpage-menu .gradient {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0.2rem;
  background: rgb(131,58,180);
  background: linear-gradient(41deg, rgba(131,58,180,1) 0%, rgba(181,73,227,1) 28%, rgba(253,29,29,1)     83%,   rgba(252,145,69,1) 100%);
}

.apply-for-org .apply-button {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translate(-50%);
  background-color: #070b0e;
  border-radius: 10rem;
  border: none;
  color: white;
  padding: 0.5rem 1rem;
  font-family: bahnschrift;
  cursor: pointer;
}

/*This section is crucial!*/
.apply-for-org > .main-wrapper {
    height: 100%;
    width: 100%;
    overflow-y: auto;
}

I may not fully understand CSS and HTML, but this solution seems to work effectively. The inclusion of the .main-wrapper element is essential for proper functioning.

EDIT: disinfor suggested an alternative approach that could potentially be successful:

To position a fixed element relative to its parent, add a transform property to the parent. Consider including transform: translate(0,0) in the parent element.

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

Get a numerical value from a JSON object

Attempting to retrieve information from an API, but encountering an issue due to a numeric property name. The method for accessing the data is as follows: Success: data[i].price_usd Unsuccessful Attempt: data[i].24h_volume_usd Have experimented with ...

Error code 0 occurs in jQuery AJAX when there is an issue with the communication between the client

Currently delving into the world of ASP.NET and wanted to create a basic website utilizing ajax to retrieve a simple string from the server. Upon running the ajax request, an error message pops up stating An error occurred: 0 error Here's a glimpse ...

The dilemma between installing Electron or installing Electron-Builder: which one

When it comes to installing Electron for an Electron app with React, the method can vary depending on the tutorial. Some tutorials use electron-builder while others do not, but there is little explanation as to why. First: npx create-react-app app cd app ...

Guide to getting Material-UI Dialog up and running smoothly in your React application

I'm currently working on a project using material-UI, and I'm having trouble with the Dialog component not working properly. Despite trying various solutions, I haven't been able to get it to function correctly in my React application with m ...

Tips for generating a single sitemap in Next.js

Utilizing the next-sitemap package to generate a sitemap, I have both dynamic and static pages. This is what my next-sitemap.config.js file looks like: module.exports = { siteUrl: 'https://example.com', generateRobotsTxt: false, excl ...

Utilizing Ajax in PHP to Upload Files

I'm encountering an issue while attempting to upload a file and send it via AJAX. The error message I am receiving is as follows: Notice: Undefined index: xlsFile in Here is the code snippet: HTML FORM : (this form is within a Modal Popup) <f ...

What could be the reason that my for loop executes only when it is embedded within a while loop?

Hey there, I've been trying to understand why this code snippet works when the while loop is included: some = 0 n = 5 while some == 0: for title in itertools.islice(driver.find_elements_by_css_selector("a[class='link-title']"), ...

React App folders are not being properly installed through NPX

Encountering an error message while attempting to use npx create-react-app Husna@LAPTOP-LPCC954R MINGW64 ~/Desktop/React GitHib Project (master) $ npx create-react-app github2020 Creating a new React app in C:\Users\Husna\Desktop\Reac ...

What is the most efficient method for retrieving an element using a data attribute with an object (JSON) value?

Imagine having the following HTML element: <div class='element' data-info='{"id":789, "value":"example"}'></div> By running this JavaScript code, you can access the object stored in the data attribute. console.log($(&apos ...

Issues with rendering components using ReactJS are causing problems with <p/> and <br/> tags not functioning as expected

I am having trouble using <p/> or <br/> tags to create new lines after a custom ReactJS component that includes Bootstrap CSS with <div className="col-sm-10">. var MyChatClientView = React.createClass({ render: function() { retur ...

Do parallel awaits in JS/TS work only on Chrome browsers exclusively?

Encountering a strange issue with promise resolution behavior in JS/TS. Using Node LTS. It seems that the difference lies in whether the promise resolves to a value that is later read in the code or if it's simply fire-and-forget (void response type). ...

Struggling to retrieve a JSON object from an Express and Node application, only receiving an empty result

Can anyone assist me? I'm having trouble with the res.json() function in my code. It seems to work after the first request, but not after the second. Right now, my application is quite simple - it scrapes user data from social media platforms like Twi ...

Learn the steps to activate on-page editing feature!

Is there a way to make a section of a webpage editable when a button is clicked? (e.g. edit & view on the same page) For instance, imagine you could click "edit" on this very page (the one you are currently reading), and the title and content become edita ...

Connecting components in React using their IDs on the same page

In my project to create a one-page website in React, I have divided it into different components such as a navbar component and an education component. My goal now is to link the navbar to the education section. In my App.js file, I am including the educat ...

Customize the List Box Appearance for a Specific HTML Item (Option)

I am working on achieving a specific behavior. When using a listBox (or comboBox), the first element (such as "choose one") should have a unique style. Here is an example of code to test: <style type="text/css"> .testX {font-style: italic;} </ ...

Step-by-step guide to creating a custom wrapper in React that modifies the props for a component

Exploring React components for the first time and seeking assistance. I am interested in dynamically wrapping one component inside another and modifying its props. For instance, considering the following component: If we want to pass the key3 from a wrapp ...

Is Firebug a necessary tool for the functioning of my website?

I'm currently tackling a new project that involves complex javascript development. Unfortunately, I am unable to share any code specifics at this time. Initially, my script functioned correctly in Firefox 3.0 but encountered issues when tested on Fir ...

The system was unable to locate node.js with socket.io

I'm having trouble locating the file. According to the documentation I reviewed, socket.io is supposed to be automatically exposed. Encountered Error: polling-xhr.js?bd56:264 GET http://localhost:8081/socket.io/?EIO=3&transport=polling&t=LyY ...

What is the best way to set the default display of the first option value in a dynamically populated <select> dropdown menu?

I have a field that displays options dynamically. I am looking to set the first option value as the default in the select field. Can someone provide assistance with this? <div class="col-lg-4"> <select name="trader" class="form-control" id="sele ...

Tips for emphasizing active tabs in Angular 6

**I have everything displaying perfectly, but I am wondering how to highlight the active tab without using any third-party components. Any assistance would be greatly appreciated. Thank you.** <ul class="tabs"> <li [ngClass]=" {'active-tab ...