Is it feasible to use both position absolute and position sticky at the same time? If so, how can this be accomplished?

Is there a way to keep an element fixed on the display without using position: fixed? I want the element to always remain above other elements, so I used z-index. Additionally, I would like the element to be able to move horizontally without scrolling across the display. Here is the code snippet I am currently working with:


<div style="position:relative;z-index:3;height:100%">
  <div style="position:absolute;bottom: -460px;right:-30px;height:100%;">
    <div style="position: sticky;top: 800px;">
      <a class="btn btn-default dropdown-toggle" style="background-color:#00AF95;border-radius:50%;margin-left:100px;" data-toggle="dropdown" onclick="$('#floatingButton').toggle();" data-hover="dropdown" aria-expanded="true">
         <i class="fa fa-plus" style="background-color:#00AF95;color:#f7f8fa"></i>
      </a>
         <div class="dropdown dropdown-inline" style="width:250px;display:block;bottom:80px;">
           <ul class="dropdown-menu SMSUI" role="menu" id="floatingButton" style="display: block;">
             <li class="dropdown" data-hover="dropdown" title="Send SMS to a Number"[enter image description here][1] onclick="(this.event.stopPropagation());">
                 <div id="numberDialerField" class="pad10R pad10L">
                    <input type="text" id="phoneCodeNumber" style="margin-left:10px;width:60px;" name="phoneCode" class="softphone-form-control" data-i18n="[placeholder]phonecode" placeholder="Ph. Code" value="">
                     <span>-</span>
                     <input type="text" id="telNumber" name="phoneNumber" class="softphone-form-control" data-i18n="[placeholder]label_phone_number" placeholder="Phone Number" value="" required="">
                       <div class="telFuncBtnDiv">
                          <span id="backspaceBtnSpan" class="cursor-pointer">
                             <i class="fa fa-check fa-xs"></i>
                          </span>
                       </div>
                    </div>
                 </li>
             </ul>
         </div>
    </div>
</div>


I have included a sample image for reference that shows what I am trying to achieve, although it doesn't quite meet my requirements. My goal is to have the movable element stay fixed without the use of position: fixed.

I want the Icon to stay at this position without position: fixed

Answer №1

To achieve this effect, follow these steps:

Step 1: Parent Element

position: absolute;
...

Step 2: Child Element

position: sticky;
top: 0;
height: 100vh;

Note: Ensure that the parent elements in the DOM hierarchy do not have overflow: hidden. If they do, change it to overflow: visible

Reminder: The child element should be assigned a fixed height, not a percentage value.

Answer №2

To ensure the element is completely independent and positioned hierarchically above other elements, my suggestion would be to relocate the div outside of any nested divs. This will detach it from being a child element of a parent with position:relative applied, potentially resolving any positioning issues you may be encountering.

Additionally, for broader browser compatibility, it is recommended to utilize fixed positioning rather than sticky.

Answer №3

Updates can be made using the position fixed to the parent with a specified height, and the child can utilize the calc CSS property to achieve the desired effect. For more details, you can refer to the link provided below.

DEMO: https://jsfiddle.net/ssuryar/02hmwkcy/11/

Parent

.position {     position: fixed;    height: 100%;}

Child

.position .row {position: absolute;    left: calc(100% - 60%);    top: calc(100% - 60%);}

Answer №4

I discovered a solution by utilizing flex within the parent container. In order to position it at the bottom-right of the element, I had to adjust the flex direction.

You can see a functioning example here

.container {
  position: relative;
  
  .parent-container {    
    height: 100%;
    position: absolute;
    bottom: 0;
    right: 0;
    display: flex;
    flex-direction: column-reverse;
    
    .sticky-item {
      width: 35px;
      height: 35px;
      background: blue;
      position: sticky;
      bottom: 0px;
    } 
  }
}

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

execute operations on a separate webpage

Currently, I am facing a challenge while developing an application that allows regular users to modify data that is typically only accessible through an admin panel. My application effectively filters out any sensitive information; however, once the data i ...

Show on smartphones, conceal on desktops - Activation/URL

I'm attempting to create a click-to-call link on my website using the following: <a class="mobile-only" href="tel:+534306464456"><p class="">Click Here to call us</p></a> I want this link to only show up on mobile devices, sp ...

Using Jquery and CSS to add a class with a 1-second delay when the mouse enters

I have successfully implemented the addClass function in my code, but I'm encountering issues when attempting to use delay or setTimeout functions. It's important to note that I'm avoiding the use of webkit attributes in CSS. If anyone has ...

Conceal content after a specific duration and display an alternative in its position, continuously repeating the loop

Imagine creating a captivating performance that unfolds right before your eyes. Picture this: as soon as the page loads, the initial text gracefully fades away after just three seconds. In its place, a mesmerizing animation reveals the second text, which ...

Implementing customized line breaks in PHP using custom fields

My knowledge of PHP is quite limited, so I prefer to seek advice from experts before attempting anything I find online. I recently installed a customized billing field plugin in order to collect additional billing information during the checkout process. ...

Guide to obtaining context vnode within vue 3 custom directives

Unable to retrieve context from directive <template lang="pug"> div(class="form") select(name="name" v-model="form.input" v-select="form.inputs") option(v-for="(option, ke ...

Is it possible to achieve the same functionality as :first-child by employing :nth-of-type without a selector?

Currently tackling a console warning related to MUI5/emotion (I believe) I have noticed that the pseudo class ":first-child" might pose potential risks during server-side rendering. It may be worth considering replacing it with ":first-of-type". I wonder ...

Troubleshooting: Issue with multiple file input elements on page - only the first input is functional and not displaying preview images

Having some trouble with loading multiple file inputs and their preview images. I've tried using getElementsByClassName but I suspect that I'm not iterating over them correctly. I want to avoid using unique IDs for the elements because they will ...

Retrieving data from websites through variable access

I'm currently facing a challenge in scraping a specific website (URL provided in the code below). When I extract the section of HTML that contains the information I need, all I get are the variable names rather than the actual values. While manually i ...

CSS styling not rendering consistently across various web browsers

Hey everyone! I've encountered an issue with my webpage. Feel free to check out the code on my CodePen here. When I view this page on Safari, everything looks perfect. However, when I switch over to Chrome or Firefox, the layout is all messed up. Ele ...

Change the color of the image to black and white and then back to its original state when a specific element is hovered over

Searching for a jQuery plugin to convert an image to black and white? Look no further! I've explored various options, but none quite fit the bill. What I'm really after is an effect that will revert the image back to color when a specific element ...

Various image dimensions cause divs to shift unevenly

Here is the current setup: <div class="row"> <div class="col-md-4 content-column"> <img class="btn-center btn-desktop" src="images/buttons/btn-desktop.svg" alt="desktop button"> <h2 class="btn-deskt ...

sending additional parameters within a URL query string

Is it even possible to include a URL with get parameters within another get parameter? For example, I'd like to pass http://example.com/return/?somevars=anothervar as the value for the "return" parameter as shown below: http://example.com/?param1=4&a ...

Adding an active class to a link tag depending on the current URL and custom Vanity URLs - here's how!

I have a functioning code snippet, but it seems to be missing a crucial part when dealing with URLs such as www.mysite.com/home/. It works perfectly fine if the URL ends with index.aspx, like www.mysite.com/home/index.aspx, but fails when that part is omit ...

Enhanced button effect: image shaded on hover

Can someone help me figure out how to make the button and image darker when hovered over? I tried something but it didn't work... Here is a demonstration: http://jsfiddle.net/h2o8w5y6/ <!--- example code snippet --> <div class="col-lg-4 ...

How can I maintain consistent spacing between two areas in CSS3 across all screen sizes?

My question pertains to the alignment of an advertisement (on the left as a banner) and content sections on my website. I have noticed that as the screen size increases, the distance between these two areas also increases. How can I ensure that the distanc ...

Methods for encoding and decoding special characters using either JavaScript or jQuery

I am looking for a solution to encode and decode various special characters using JavaScript or jQuery... ~!@#$%^&*()_+|}{:"?><,./';[]\=-` I attempted to encode them using the following code snippet... var cT = encodeURI(oM); // ...

Ways to align three divs next to each other in an HTML structure?

I am currently working on a website layout that consists of three sections positioned horizontally. I am aiming for the left division to take up 25% of the width, the middle one to occupy 50% of the width, and the right division to fill 25% of the width so ...

"The Zorro table is filled with items of various types, although unfortunately, the Intellisense is not as accurate as it

Imagine a scenario where you have a basic table set up: <nz-table #table [nzData]="users"> <thead> <tr> <th>Id</th> <th>First Name</th> <th>Last Name</th> </tr> ...

Modifying a section of the source name using jQuery continues to occur repeatedly when the window is resized

I have written a piece of code that is designed to identify the src attribute of all images within a specific div and modify the src name when the window width is less than 900 pixels. The code works perfectly when the page is refreshed, but I encounter an ...