Tips for Preventing Navigation Bar from Triggering Scrolling

I am experiencing an issue with my navbar and body container. Whenever the navbar is present, the page automatically scrolls vertically. However, when I remove the navbar, the scrolling behavior stops.

What is causing this scroll behavior with the navbar? How can I prevent the window from scrolling when the navbar is still in place?

    .wrapper {
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
      }

      .main {
        flex: 1 0 auto;
        /*overflow-y: auto;*/
      }

      .inner {
        flex: 1 0 0;
        overflow-y: auto;
        /*
    min-height: 100%;
    max-height: 100%;
    */
      }

      .sidebar {
        overflow-y: auto;
      }

      .content {
        overflow-y: auto;
        flex-grow: 1;
      }
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b7babaa1a6a1a7b4a595e1fbe0fbe7">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand navbar-light bg-white topbar shadow">
  <a class="navbar-brand" href="#">ENG</a>
</nav>
<div class="container-fluid">
  <div class="wrapper row">
    <div class="col-9 mh-100 inner d-flex flex-column p-0">
      <div class="main bg-info p-3 d-flex flex-column">
        <div class="p-3 content">
          <h3>Main content area</h3>
          <p>
            Voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolornon numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
            Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur...
           </p>
        </div>
        <div class="bg-faded p-3">
          inner footer (stick to bottom of content area)
        </div>
      </div>
      <footer class="bg-inverse text-white p-3">
        footer (stick to bottom of left)
      </footer>
    </div>
    <div class="col-3 mh-100 bg-faded p-3 sidebar">
      <h3>Sidebar</h3>
      <p>
        This content should scroll independently if needed...
      </p>
    </div>
  </div>
</div>

The source reference for this example is located here: Flexbox height issue with nested flex-grow boxes in Bootstrap 4

To view the actual problem and code snippet, visit:

Answer №1

You could experiment with using overflow-x: hidden; or overflow-y: hidden; in your navbar class to control scrolling either horizontally or vertically.

Answer №2

Could you please review this for me? :)

 .wrapper {
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
      }

      .main {
        flex: 1 0 auto;
        /*overflow-y: auto;*/
      }

      .inner {
        flex: 1 0 0;
        overflow-y: auto;
        /*
    min-height: 100%;
    max-height: 100%;
    */
      }

      .sidebar {
        overflow-y: auto;
      }

      .content {
        overflow-y: auto;
        flex-grow: 1;
      }
body{overflow-y: hidden;}
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7959898838483859687b7c3d9c2d9c5">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand navbar-light bg-white topbar shadow">
  <a class="navbar-brand" href="#">ENG</a>
</nav>
<div class="container-fluid">
  <div class="wrapper row">
    <div class="col-9 mh-100 inner d-flex flex-column p-0">
      <div class="main bg-info p-3 d-flex flex-column">
        <div class="p-3 content">
          <h3>Main content area</h3>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec imperdiet est. Proin non tortor nec nulla tristique suscipit.
            Aliquam erat volutpat. Sed euismod mi sed facilisis posuere. Nullam quis sem eget velit tincidunt elementum ac a lectus.
            Mauris vitae sapien et orci consequat tristique nec sed metus. Curabitur neque arcu, venenatis sed quam ut, hendrerit finibus urna.
            Ut commodo enim augue, pellentesque blandit tellus aliquet in.

          </p>
        </div>
        <div class="bg-faded p-3">
          Content footer at the end of the main content area.
        </div>
      </div>
      <footer class="bg-inverse text-white p-3">
        Footer fixed to the bottom left side.
      </footer>
    </div>
    <div class="col-3 mh-100 bg-faded p-3 sidebar">
      <h3>Sidebar</h3>
      <p>
        This is the sidebar content that can scroll independently if needed. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>
  </div>
</div>

Answer №3

.wrapper {
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
      }

      .main {
        flex: 1 0 auto;
        /*overflow-y: auto;*/
      }

      .inner {
        flex: 1 0 0;
        overflow-y: auto;
        /*
    min-height: 100%;
    max-height: 100%;
    */
      }

      .sidebar {
        overflow-y: auto;
      }

      .content {
        overflow-y: auto;
        flex-grow: 1;
      }
nav.navbar.navbar-expand.navbar-light.bg-white.topbar.shadow {
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 9;
}

.container-fluid {
    margin-top: 60px;
}
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53313c3c27202721322313677d667d61">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand navbar-light bg-white topbar shadow">
  <a class="navbar-brand" href="#">ENG</a>
</nav>
<div class="container-fluid">
  <div class="wrapper row">
    <div class="col-9 mh-100 inner d-flex flex-column p-0">
      <div class="main bg-info p-3 d-flex flex-column">
        <div class="p-3 content">
          <h3>Main content area</h3>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nec sem at lectus pharetra accumsan vel et libero.Vivamus vulputate neque in urnablandit a sit imperdiet magna egestas. Phasellus metusvel varius tortor praesent erat ligula amet nisl.fringilla fames congue porttitor quisque semper.sociosqu dis massa ferme pede eget cubilia.equet etiam sollicit tincludunt nisi tempus aenean.natoque cre gravida mattis seddonec quis leo justo in vestibulum orci.euismod integer.massa lobortis risus ante pulvinar.placerat sedcom Bayer non eros fac ilisis done saattthabitasse proin ligulamagna habitant tinc ID laore stipoltti suces.</p>
        </div>
        <div class="bg-faded p-3">
          Footer text here
        </div>
      </div>
      <footer class="bg-inverse text-white p-3">
        Footer text here
      </footer>
    </div>
    <div class="col-3 mh-100 bg-faded p-3 sidebar">
      <h3>Sidebar</h3>
      <p>
         This is the sidebar content that can independently scroll if needed.
      </p>
    </div>
  </div>
</div>

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

Automatically generated JavaScript input value calculation

I have 3 text input fields set up as follows: <input type="text" id ="text1"/><br> <input type="text" id ="text2"/><br> <input type="text" readonly="readonly" disabled="disabled" id ="text3"/> The third input is disabled and ...

Setting image height for consistent display across all browsers

I have searched both this forum and Google before posting this question, but unfortunately, the methods provided do not seem to work for me. Perhaps I am doing something incorrectly. The page I am working on looks like this: enter image description here ...

Difficulty in implementing a radio button selection form using Django and Bootstrap styles

Currently, I am facing an issue while trying to develop a form with radio button choices using Django. The website is based on Bootstrap 4 theme and encountering a problem where the buttons disappear upon applying the custom-control-input class. I initial ...

Aligning items vertically within a container with a constant height

I'm currently working on a website that requires a pixel-based navbar with a height of 80px. The issue I'm facing is the difficulty in vertically centering the ul and li elements. I have experimented with various methods such as using top:50%; ...

Creating a Form with Dynamic HTML when Button is Clicked

I have been working on enhancing the functionality of my website app located at , but unfortunately, I have not been successful so far. My goal is to introduce a vendor information form with just one click of a button and then enable users to add products ...

Attempting to create a JavaScript calculator from scratch

After spending hours typing and debugging my code for a school assignment, I have created a calculator that still isn't working. I'm hoping someone can help me find the errors in my code. function myStory() { window.alert ("Very doge"); } // ...

Combining Django and chartjs to create stacked multiple charts

Hey there! I'm working on a Django application and using Chart.js to create bar charts. I encountered an issue where, after generating a new chart with a button click, the old one still lingers behind when hovering over the new chart. I have a suspici ...

Verify if an item is already present in the HTML document before adding a new item to it using Ajax

I am working on a page that displays a list of new students with the option to accept or reject them. The list can be updated in two ways - by manually refreshing the page, or through an Ajax method that automatically updates the list when a new student re ...

Use JavaScript to limit Google Analytics and Yandex.Metrica to track only the referral sources and screen sizes

I prefer not to include external JavaScript on my website for unnecessary tracking purposes. However, I do need to gather referrer and screen size information, which cannot be achieved with a regular HTML img tag alone. What is the most standard-complian ...

Sudden slowdown due to Jquery error

I am encountering an issue with the Jquery registration validation. I am struggling to display the error message if a name is not filled in. jQuery(document).ready(function () { $('#register').submit(function () { var action = $(thi ...

Use custom styles or CSS for the file input element: <input type="file">

Can CSS be used to achieve consistent styling for <input type="file"> in all browsers? ...

rendering google charts using jade template

I am facing an issue while trying to display a google annotated chart on my jade project. I managed to successfully load a pie chart, but I am having trouble rendering a chart that requires the container element size to be explicitly defined. You can find ...

Deactivate hover effects and media queries for Material UI controls in all states

Since I am using a touch-capable monitor, I noticed that hover styles are not showing up on any controls. Specifically, when I hover over a Material UI button, I see the following styles: https://i.stack.imgur.com/uwBpt.png Is there a way to disable all ...

The issue of the back button not functioning in the React Multi-level push menu SCSS has

I have been developing a mobile-friendly Multi-level push navigation menu for my website using dynamically generated links based on projects from my GitHub account. I found a push menu on CodePen here and am in the process of integrating it into React inst ...

Ways to align items in the middle of a list

I'm having trouble figuring this out. How can I properly center list items within the ul? body {margin: 0} ul { width: 1000px; margin: 0 auto; padding: 0; list-style-type: none; margin-top: 30px; overflow: hidden; background-color: # ...

The ideal location for the style.css file in a WordPress website

I'm currently working on creating my own WordPress theme and utilizing SASS to write the CSS. I want the final compiled CSS to be minified, so I have a question: If I set SASS to compile the CSS in my style.css file (located in the main theme folder) ...

incorporating video content onto a webpage

Let me provide more details for better understanding. Currently, the website is not operational yet. Once it's live, I'll be hosting it on a platform like YouTube. The issue I encountered was when trying to embed a video using the code below: & ...

Is there a way to continually repeat a hover effect?

Currently, I am focusing on creating a timeline and have managed to get the basic function working in jQuery. You can view my progress on jsFiddle here: http://jsfiddle.net/Jason1975/6nwkd2c8/38/ The issue I am facing is that I cannot get the hover effect ...

Obtaining the name property of an uploaded file in javascript

I've gone through multiple forums and cannot seem to find the solution to my issue. If I overlooked it, I apologize for any duplication. I currently have a basic event handler set up for file submission in a form. Here is the code: onChange(e) { ...

Css flex is not compatible with Safari, iPhone 5, and some mobile web browsers' webviews

All of the following code snippets are written in HTML: <div class="btn-toolbar text-center" role="toolbar"> <a href="#" class="btn btn-success">Link 1</a> <a href="#" class="btn btn-success">Link 11</a> < ...