Customize Bootstrap 4 scrollbar overflow with a sticky-top feature

Currently, I have a layout consisting of two rows: the first row is fixed to the top of the screen using sticky-top, and the second row fills the remaining height on the screen with min-vh-100. New content will be added dynamically to the second row's innerHTML, and I want the user to always see the first row as overflow is managed by a scrollbar.

The initial problem arises when a scrollbar appears upon document load/ready, allowing users to scroll down so that part of the content in the second row gets hidden behind the first row. This issue seems to be related to sticky-top, but I'm unsure about how to resolve it. Ideally, a scrollbar should only appear if there is overflow in the second row due to added content. Users should not be able to scroll down and lose sight of the content hidden by the first row.

The next challenge is ensuring that the scrollbar automatically scrolls as new content is added to the second row. I attempted to manipulate the body's scrollTop and scrollHeight properties without success. In the Codepen example provided, scrolling down to hide "Hello" should not be possible.

<!DOCTYPE html>
<html>
<meta charset="utf-8">

<head>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

  <style>
    label:hover {
      background: LightGray;
      cursor: pointer;
    }
  </style>
</head>

<body class="bg-light">
  <div class="container-fluid">
    <form name="form" enctype="multipart/x-www-form-urlencoded" action="/execute" method="post">
      <div class="row">
        <div class="col">
          <div class="row pt-2 pb-4 align-items-center justify-content-center bg-light sticky-top">

            <button class="submitbutton btn btn-info" type="submit" name="Help" value="Help">Help</button>

            <div class="ml-4 mr-4">
              <input class="form-control mt-2" type="text" name="Textbox">
            </div>

            <button class="submitbutton btn btn-success mr-4" type="submit" name="Go" value="Go">Go</button>
            <button id="cancel" type="button" class="btn btn-dark">Cancel</button>

          </div>

          <div class="row bg-dark">
            <code class="pl-4 text-white min-vh-100">Hello</code>
          </div>

        </div>
      </div>
    </form>
  </div>
</body>
</html>

Codepen

I prefer maintaining the use of rows and columns within this layout since it's integrated into a larger grid design.

Answer №1

If I understand correctly, the approach I would take is to include this code:

min-height: calc(100vh - 78px); // Adjust the px value based on the sticky-top height

View Example on Codepen

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

The functionality of WebDriver Wait is not functioning as expected

Is there a way to avoid waiting for the entire page to load? I thought using WebDriverWait would help, but I keep getting a TimeoutException even though the tag is visible. self.driver.get('http://www.quoka.de/') self.wait.until(EC.invisibility_ ...

Body section CSS selector

Can a CSS selector be included within the body section of an HTML document? Here's an example of my code (although it is not functioning as expected): <html> <head> </head> <body> <div style= "a[target=_blank] {backgroun ...

What is the best method for animating a display table to none or reducing its height to

My goal is to animate a header whenever the class collapseTest is applied. After some trial and error, I have come up with the following solution: http://jsfiddle.net/robertrozas/atuyLtL0/1/. A big shoutout to @Hackerman for helping me get it to work. The ...

How to incorporate spacing within table rows using HTML

I am trying to create a table with rows starting from different positions like this 12345 678910 This is my code <table class="center"> <tr style="padding-right: 22%"> <td>1</td> <td>2</td> ...

Is it necessary for each React component to have its own individual stylesheet?

Looking for some advice on React as a newbie here. I'm wondering whether each React component should have its own stylesheet. For instance, if I have my main App component that gets rendered to the browser, is it sufficient to include a CSS file the ...

Backdrop dimming the Material UI Modal

My modal is designed to display the status of a transaction on my website, but I'm facing an issue where the backdrop dimming effect is being applied over the modal. Instead of appearing white as intended, the modal ends up having a dark gray tint. I ...

Error: Unable to interpret the rest of the code: '/bootstrap4/popper.js' from 'styles/bootstrap4/popper.js'

I set up the static directory to load a template, but I encountered an error: {% load static %} The error message reads: django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '/bootstrap4/popper.js'' from 'styl ...

Retrieve the value of another ID within a form using the .innerHTML property

I would like to be able to show the value of a text field when the Search button is clicked. Currently, I have the following code on the search button: onclick="document.getElementByid('output').innerHTML = this.value" This code successfully r ...

Add together the values retrieved from various AJAX calls

I'm attempting to calculate the total value of the data returned by multiple ajax requests. However, I am facing an issue where the total is always showing as 0 because the calculation is happening before the ajax requests are completed. var totalRev ...

Use JavaScript to dynamically generate a drop-down select menu

Is there a way to automatically expand a select menu dropdown using JavaScript or jQuery when a button is clicked? I am facing this challenge because I have a text field that allows users to input custom fields dynamically into a select input. My goal is ...

Adding dashes as padding in HTML/CSS

I am currently working on updating the user management block on my website and I want to showcase it with some visual examples. I believe that using images is the most effective way to demonstrate changes. This is the current appearance of the block: ...

Looking to eliminate the vertical spacing of the <hr> tag?

Summary: For a quick solution, just click on the image at the bottom. Greetings to everyone! I am facing an issue with two <div> elements that I need to separate using a <hr class="separator"> element. Below is the CSS code for the ...

Jquery code malfunctioning on Django paginated webpages

I've tried countless things and searched high and low, but nothing has seemed to resolve my issue. Issue: I have a jQuery script that functions perfectly on the initial page, but fails to run on subsequent paginated pages. I encountered a similar pro ...

Issues with displaying the grandparent of the nearest element using jQuery

I have some HTML below (generated using CakePHP): I am attempting to display the grandparent element of the closest element that was clicked: $('.what_is_the_quote_for').closest('.form-group').hide(); $('.visit_status').cha ...

Achieving a dynamic scrollable table that adjusts its height based on its parent container (HTML + Bootstrap)

I am trying to create a table that can be scrolled vertically using the standard overflow: auto property without specifying a set height for the table's container. While Bootstrap provides a class called table-responsive for handling horizontal scrol ...

Poor response to Ajax request when combined with an else statement

I am currently utilizing Ajax in conjunction with a form to provide user feedback upon submission, indicating whether the process was successful (no errors) or if any input is missing. My approach is quite straightforward as I am using the XMLHttpRequest o ...

Is there a jQuery AJAX method that can be invoked during the waiting process for error, success, or completion?

As I was about to use an ajax function and looking through the API, a question popped into my head. Is there a way to execute a function while waiting for the success, error, done, etc. callbacks to be triggered? I wondered if there could be something lik ...

Is there a way to execute a Python script when submitting an HTML form?

I have created an HTML form and my goal is to utilize Python to transfer the data from this form into an SQLite database file. Currently, I am attempting to achieve this using CGI. I don't require anything extravagant. Below is the code that I am work ...

Caution: The presence of <li> within another <li> is not permitted in validateDOMNesting()

I am facing a challenging background error warning that I am struggling to solve. As a beginner, I understand the need to change li, but I'm not sure where to begin. Can someone please assist me with this error warning: next-dev.js?3515:20 Warning: va ...

Styling CSS: Adjusting font sizes for placeholders and text boxes

I am struggling with styling an input field to have a font size of 45px while the placeholder text inside it should be 18px and vertically aligned in the middle. Unfortunately, my current code is not working in Chrome and Opera. Can anyone offer a solutio ...