Issue with Sticky Positioning in Bootstrap Column

Looking for some help with making my form sticky while users scroll past other content on the page.

I've used this method successfully before, but for some reason it's not working this time. Can anyone shed some light on why my form won't stick in this instance?

.sticky-top {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 1020;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />


<div class="container">
  <div class="row justify-content-around">
    <div class="col-5">
      <!-- sticky -->
      <div class="sticky-top">
        <div class="card card__body box-shadow" style="background-color:green;">
          <div class="row">
            <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12 ">
              <div class="form-group service-form-group">
                <label class="control-label sr-only" for="name"></label>
                <input id="name" type="text" placeholder="First Name" class="form-control" required>
                <div class="form-icon"><i class="fa fa-user"></i></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-lg-5 col-12">
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
      <h2>Placeholder</h2>
    </div>
  </div>
</div>

Answer №1

By making some adjustments, I was able to resolve the issue of the form not sticking by removing certain column classes and including a row to the placeholder grouping.

Here is the updated code:

.sticky-top {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 1020;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />


<div class="container">
  <div class="row justify-content-around">
    <div>
      <!-- sticky -->
      <div class="sticky-top">
        <div class="card card__body box-shadow" style="background-color:green;">
          <div class="row">
            <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12 ">
              <div class="form-group service-form-group">
                <label class="control-label sr-only" for="name"></label>
                <input id="name" type="text" placeholder="First Name" class="form-control" required>
                <div class="form-icon"><i class="fa fa-user"></i></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
        <h2>Placeholder</h2>
      </div>
    </div>
  </div>
</div>

Please let me know if this meets your requirements.

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

Flex children do not adhere to max-height and max-width properties

There seems to be an issue with setting the max-width and height for flex children. The div is getting squished down to fit its children exactly, possibly due to the styling associated with div .content. It's not clear why this is happening. The divi ...

Issue with fixed sidebar on brief content

It's interesting how the sticky widget performs differently on long articles compared to short ones on my website. Here is an example of a long article where the sticky widget works well without any lag: . Now, let's take a look at a shorter art ...

how to make a div scroll after reaching a specific pixel distance

Hi there! I'm working with a DIV that has a width of 1600px. I'm wondering if there's a way to implement a feature within the DIV that fixes the first 200px and adds an automatic scroll for the rest of the content. Do you know of any CSS tr ...

Ways to position Bootstrap 4 navbar elements at the bottom

Struggling to adjust the alignment of the text in the navbar items using Bootstrap 4? My initial thought was to align them at the bottom of the ul and then position the ul accordingly, but I'm facing challenges with both. The objective is to have the ...

Is there a way to keep this function running endlessly when hovering?

Is there a way to modify this function so that the classes of my links continuously change colors while I hover over them, rather than changing only once? <script type="text/javascript"> $(".nav a").hover(function(e){ var randomC ...

Display icons within each table cell row

Objective: I want to implement a feature where icons appear when the cursor is inside a td row, allowing users to click on them. These icons will contain links. When the cursor moves to a new td row, the previous row should return to its default state a ...

The CSS functionality for the body tag operates seamlessly even without the presence of the body tag in the

My style.css file has the following code: body{ background-color:pink; font-size: 130%; } This is the code in my style_placement.html file: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

Unusual actions observed when using CSS pseudo selector :checked

I have implemented a unique CSS solution to showcase a five-star rating system on my website. The method I followed can be found at . While this technique works flawlessly in some sections of my website, it strangely fails in others. Could this be due to c ...

Applying a Webkit Scroll Bar to a specific element on the webpage

I've been attempting to apply the Scroll Bar webkit styling to a particular element but haven't had any success. Despite searching extensively, I have come across 2 threads on Stack Overflow that do not provide a solution. Most of the available ...

Implementing Multiple Shared Footers in Rails 3

Looking for a solution to display unique footers in Rails? For instance, displaying one footer on the homepage and another footer on the rest of the site. Has anyone successfully implemented this before? I was considering using an if statement based on th ...

Include toggle attribute in v-b-popover for touch functionalities

Currently, I am implementing v-b-popover on my website to handle both touch and mouse events. To achieve this, I have set the tag of v-b-popover as 'hover'. I am wondering if there is a way for me to toggle the popover (show and hide) for both to ...

Paths to External Stylesheets

Imagine having a stylesheet body { background-image: url('/images/background.jpg'); } situated in the header section of a nearby document <html> <head> <link rel="StyleSheet" href="http://externalserver/stylesheet.cs ...

The table spills over the container and disappears underneath the navbar

After downloading a template table from the internet and customizing it to my liking, I encountered an issue where it does not adhere to the assigned settings (as shown in the image), but that's not the only problem. The dropdown navbar on my website ...

Ways to conceal an item by considering the size of a different element

I have a question about displaying content within a div element. I want to show a "show more" button only if the content inside the div exceeds a max height of 530px. Otherwise, the button should remain hidden. Here is the code snippet I'm using: Ja ...

Is it possible to simultaneously employ two asynchronous functions while handling two separate .json files?

Is it possible to work with 2 .json files simultaneously? My attempt did not succeed, so I am looking for an alternative method. If you have a suggestion or know the correct syntax to make this work, please share. And most importantly, does the second .j ...

Stop jQuery popups from wrapping text when resizing the browser window

Whenever a link is clicked, a jQuery popup appears. The popup functions properly in terms of opening and closing, but I would like to ensure that its position remains fixed when resizing the browser window to avoid any wrapping issues. Typically, I use a ...

What could be causing the HTML <DATALIST> dropdown to display next to its input rather than below it?

I have an input linked to a datalist, and it's functioning correctly. However, when I initially open the dropdown, the option list appears next to (right of) the input. After entering a few characters to narrow down the list, it then shifts below the ...

Instructions for creating a fading effect on W3schools Modal example

After utilizing the CSS class from https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_modal_fade to achieve a fade in effect, I am now looking for a way to fade out when the modal closes. How can this be accomplished? .w3-animate-opacity{animatio ...

The Reason Behind Angular Error when Using CSS Custom Tags

I have the following SCSS code: main{ width: 100%; height: 840px; /*background: red;*/ margin: 10px auto; position: relative; padding: 5px 0; } section{ width: 98%; height: 600px; margin: auto; display: flex; ...

Determine the top margin of an element

Looking to position my text with a 100px top margin, similar to this: Any ideas on accomplishing this? The font size should be 24pt and bold. ...