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

Maintain HTML formatting when page is refreshed

I am new to HTML and JavaScript, and I'm trying to modify the JavaScript code below so that when I reload the page, it retains the most recent active tab instead of defaulting back to the first tab. Currently, if I click on the second tab for "Paris" ...

Guide on how to smoothly navigate through an HTML page to a specific anchor point

Is there a way to use JavaScript to make the browser scroll the page to a specific anchor? In my HTML code, I have set either a name or id attribute like this: <a name="anchorName">..</a> or <h1 id="anchorName2">..&l ...

Utilizing Angular's Scope Functionality

I am a novice in the world of AngularJS. Currently, I am delving into the expert's codebase and looking to customize the directives for educational purposes. Interestingly, the expert consistently includes: this.scope = $scope; at the start of eac ...

Enhancing CKEditor: Inserting new elements upon each dialog opening

I am facing a challenge where I need to dynamically add varying numbers of elements to a dialog window each time it is opened. Below is the code I am working with: CKEDITOR.on( 'dialogDefinition', function(ev) { var dialogName = ev.data.name ...

Pressing ctrl+s will submit TinyMCE+JEditable

Updated: June 8th, 2011 Please check out the solution provided in the Answer section below. Updated: May 5th, 2011 I am currently facing a challenge where I need to trigger the JEditable submit button after hitting Ctrl+S. Thariama has already demonstr ...

What is the best way to retrieve the column that comes after a specific column?

I have a specific column and I want to extract the subsequent column in the dataset. nhood,column,variablecolumn Treasure Island,3,5 McLaren Park,1,2 Tenderloin,28,112 Lakeshore,14,8 Chinatown,15,103 Although I know the name of the second column, the na ...

Adjusting the placement in Draw2D

I'm a newcomer to this library and I'm struggling to figure out how to properly size and position the canvas. If anyone could provide guidance on the best way to do this, I would greatly appreciate it. $(window).load(function () { // se ...

Unable to execute redirect function in Next.js 14 application

I've been working on implementing basic authentication within a Next.js app, however I'm encountering issues with redirecting to the homepage from the auth.ts file. Below is a snippet of the code where I am implementing the loginForm: //loginForm ...

Display the number of likes without having to refresh the page

On my website, there is a like/unlike post feature. When I click the like button, I want the value of check2 to appear next to the like button without needing to refresh the page. Currently, after clicking like, the data is inserted but only appears after ...

eliminating various arrays within a two-dimensional array

I need help with a web application that is designed to handle large 2D arrays. Sometimes the arrays look like this: var multiArray = [["","","",""],[1,2,3],["hello","dog","cat"],["","","",""]]; I am looking to create a function that will remove any array ...

What are the steps for translating multiple meshes in various directions using three.js?

One issue that I am encountering involves creating 100 meshes with a for loop, all of which have the same position coordinates of 0,0,0. I would like these meshes to move in different directions individually. Below is my code for creating the 100 meshes: ...

Ways to retrieve a variable within the init() function

My current project involves using datatables along with ajax to display information dynamically. Below is the code snippet I am working with: // Setting up the module var DatatableAdvanced = function() { // Examples of Basic Datatables var _c ...

Recording audio using Cordova and Javascript

Recently, I've been dabbling in creating a new app using Cordova, VueJs, and Onsen UI for VueJs. One of the main features I want to implement is the ability to use the microphone on Android or iOS devices to record audio and then send it to the Google ...

Links are functional in browsers, but seem to be unresponsive on iPad devices

I'm currently developing a website that allows users to navigate using swipe gestures. Each slide contains multiple links that should redirect users to different locations upon clicking. However, I've encountered a bizarre issue where the links a ...

Can you guide me on setting up a multi-selection option for a field in my Wordpress Theme by Templatic?

My website is http://aisiel.ro, a real estate agency website. Under the slider, there is a search field where we have the option to select an area called "Zona" - Area in English. Currently, users can only choose one area for their search, but I want to ...

Integrate actual credentials into S3Client using redux async thunk

My S3-like react application with redux is powered by AWS SDK v3 for JS. The client initialization in my auth.js file looks like this: auth.js export const s3Client = new S3Client({ region: 'default', credentials: { accessKeyId: 'te ...

creating center-focused gradients in react native using LinearGradient

Hey there, I'm currently facing an issue with applying a box shadow to one of the buttons in my React Native application. Unfortunately, the box shadow property is not supported in Android. To work around this limitation, I am experimenting with creat ...

In Internet Explorer 8, experiment with creating a unique event in plain JavaScript and then capturing it using jQuery

Currently, I am facing an issue with IE8 regarding the execution order of scripts. There is a piece of code that needs to run before JQuery is loaded so I can fire a custom event. This event will be detected later by another section of code once JQuery ha ...

The rendering of the font appears distinct when viewed on an iPad compared to when displayed

Visit this website. The menu displays correctly on desktop, but on iPads, the font appears larger leading to a line break. Is it because the selected font isn't loading and defaulting to Times New Roman instead? It seems likely since I experience the ...

When Vue detects a change in declared parameters from an empty string, it automatically sends a

Within my application, I am making a request to the backend app and receiving a response with an ID such as { 'id': '12345'}. This ID is then saved as loadId within the data object: export default { name: 'SyncProducts', d ...