The vertical scrolling issue arises when the content exceeds the height of the screen

Seeking a solution to enable scrolling of users within a flexbox menu, I've come across an interesting discovery. When setting a specific height in pixels for my nav element (like 100px), everything works perfectly. However, when I set the height to 100%, a global scroll appears if there isn't enough space and my menu doesn't fit the screen size.

I have created two CodePens to illustrate the issue:

100% height for nav (scroll not working) -

https://codepen.io/Shalev1104/pen/oNGYGgX

Height with pixels (working scroll) -

https://codepen.io/Shalev1104/pen/KKXNXdB

*The only difference between them is the height property inside the <nav> tag.

If it's still unclear, I'm looking for a vertical menu that occupies 100% of the screen and has a vertical scroll within all available spaces. Your assistance would be greatly appreciated.

Answer №1

Percentages serve as a comparison to what? (e.g., 100% of ...what?). Ensure that each parent element above the navigation also has a defined height.

For instance, if your website is structured like this:

<html>
  <body>
    <ul class="nav">...</ul>
  </body>
</html>

The following CSS code will probably resolve your issue:

html, body, ul.nav { height: 100%; }

Edit: Here's a more organized version in both HTML and CSS:

<html>
  <body>
    <ul class="nav sidebar">
      <li class="nav-item sidebar-top">
        <div class="input-group">
          <input type="search" class="form-control" placeholder="Search Chat" />
          <button class="btn btn-secondary" type="button">Search</button>
        </div>
      </li>
      <li class="nav-item sidebar-middle">
        <nav>
          <li>d</li> <!-- repeated for brevity -->
        </nav>
      </li>
      <li class="nav-item sidebar-bottom">
        <div class="d-flex justify-content-between align-items-center px-3">
          <div>
            <img src="https://www.jquery-az.com/html/images/banana.jpg" class="rounded-circle" width="50" height="50" alt="profile" />
            <span class="ms-2">User 1</span>
          </div>
          <button class="btn bi-box-arrow-left">&nbsp;Disconnect</button>
        </div>
      </li>
    </ul>
    <main>
      <p>content on the page....</p> <!-- repeated for brevity -->
    </main>
  </body>
</html>

html, body {
  margin: 0; padding: 0;
  height: 100%;
}
body {
  display: flex;
  flex-flow: row nowrap;
  width: 100%:
  background-color: red;
}
main {
  flex: 1 0 0;
  overflow-y: scroll;
}
.sidebar {
  margin: 0 20px 0 0; padding: 0;
  list-style-type: none;
  height: 100%;
  display: flex;
  flex-flow: column nowrap;
  flex: 0 0 auto;
  background-color: red;
}
.sidebar-top {
  margin: 0; padding: 5px;
  flex: 0 0 auto;
  background-color: green;
} 
.sidebar-middle {
  margin: 0; padding: 5px;
  flex: 1 1 auto;
  overflow-y: scroll;
  background-color: yellow;
}
.sidebar-bottom {
  margin: 0; padding: 5px;
  flex: 0 0 auto;
  background-color: blue;
}

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

Styling a fixed sidebar in Vue.js

I am currently working on a layout design that includes a fixed sidebar on the left side, positioned beside a container with its own grid structure. Utilizing Vue.js means each template contains <div> elements where I attempt to incorporate additiona ...

Is there a way to adjust the height relative to the viewport in Bootstrap 5 for values other than 100?

Attempting to create a new type of div using a custom stylesheet with minimal non-bootstrap css. I am trying to convert each style rule from my django static files CSS into a bootstrap class, but I am stuck on viewport-based sizing. Prior to discovering t ...

When I try to call jQuery's getScript function, the callback does not execute as expected within

When I invoke the script in a function at runtime function CheckOutMyFace() { $.getScript("/scripts/jtimers.js", function (data) { }); }; I notice in Firebug that the script is being called every time the function is invoked, but for some reason the ...

`The height attribute of the textarea element is not being accurately adjusted`

When I tried to match the width(178px) and height(178px) of my table to the width and height of a text area upon clicking a button, I encountered an issue. While setting the width works perfectly fine, the height is being set to only 17px. It seems like ...

How can I style an image in CSS to have a set height, maximum width, and keep its aspect ratio fixed?

I am trying to place a set of images with varying heights and widths inside a div tag. My goal is to have the images maintain a fixed height, unless the width surpasses a certain limit, in which case I want the height to adjust while preserving the aspect ...

Manipulate the CSS of a single div within a group of divs that have the same class using jQuery

I'm attempting to modify the CSS of a specific DIV that shares its class with other divs. I've searched for a solution but haven't had any luck so far. Here is the code I've been using without success: $(".singleOffer").click(functio ...

Is there a way to determine if jQuery lightslider has been initialized, and if so, how can I effectively remove the instance?

Currently, I have integrated the JQuery lightSlider into my project. Despite some code adjustments, it is functioning well. My goal is to dynamically replace the lightSlider content with data returned via AJAX, which I have successfully achieved. After r ...

Unusual behavior observed in Safari regarding transitions and animations

I have encountered a strange bug in Safari 8 and 9 on desktop, as well as iOS 8.4 and newer on mobile devices. I am perplexed by why it is happening and how to resolve it. This issue can be replicated with 100% accuracy. Here are the steps to reproduce: ...

Is it possible to conceal a link once it has been visited?

I am trying to figure out how to remove a link from a page once it has been visited. However, I am facing privacy restrictions with the :visited pseudo-class. Is there a way to achieve this without using display: none? For example: .someclass a:link {dis ...

What is the best way to stylize a date using Bootstrap-datepicker?

While this topic is well-known, I have a slightly more complex question regarding it. I have gone through the documentation here. My goal is to display the date in French format (dd/mm/yyyy) and save the value in US format (yyyy-mm-dd). Additionally, I nee ...

What is the best way to ensure the search box remains fixed in the top navigation bar while maintaining a fluid and responsive design?

I've been struggling as a novice programmer, and even with the help of more experienced programmers, we haven't been able to figure it out. I'm trying to integrate a search box into the top navigation that adjusts responsively to different ...

Tips for creating CSS3 animations in Angular triggered by mouse clicks

I'm working with a span that utilizes a Bootstrap icon. My goal is to fade out and fade in the same element (span) on click, while toggling the class (icon). There's a boolean variable called showLegend which determines whether or not to animate ...

Building CSS Using TagBuilder in .NET Core

Can you provide guidance on utilizing the Tag Builder CSS Class? I am interested in integrating it into a style class .custom-image { max-width: 100%; max-height: 100%; padding: 0; background-color: white; } TagBuilder image = new TagBuilder("img"); Wh ...

What's the trick to making a column that's 2/3 wide in a 34grid layout?

Is it possible to use the 34 Responsive Grid system to create a column that takes up two-thirds of the full width? Although the Grid System has equal columns settings, I'm curious how to combine or merge two columns together? <div class="containe ...

What is the best way to show a select list on top of another element?

I'm currently working on a project using this React Template. Within one of the components, there's a Select List followed by a Card element. The issue arises when I click on the list, as the items appear beneath the card: Upon investigating ...

What could be causing the issue of CSS Styles not being applied to an Angular 2 component with Vaadin elements?

Currently, I am immersed in the tutorial on Vaadin elements using Angular 2 that I stumbled upon here In section 5.3, Styles are applied to the app.component.ts as shown below import { Component } from [email protected]/core'; @Component({ select ...

What is the best way to extract a color box from a Bootstrap container?

After trying multiple solutions found online, I'm still struggling to break out of the bootstrap container as needed. The setup involves a .fluid-container for a full-width background behind a regular .container. The challenge arises when the first co ...

AngularJS is used to vertically collapse three different div elements. This feature

I am facing an issue with the design of my page that contains three panels. Two of these panels have tables, and when viewing the page on a smaller display, it disrupts the layout. I am wondering if there is a way to add collapsible buttons to the panels s ...

Expanding the width of CSS dropdown menus according to their content

When attempting to create a dynamic dropdown menu, I encountered an issue where the values were skewed in Internet Explorer if they exceeded the width of the dropdown. To fix this problem, I added select:hover{width:auto;position:absolute}. However, now th ...

Fluid Bootstrap Container for x-small and small screens

Is it possible to have the outer-most div container named "container" for md and lg, while using container-fluid for xs and sm without any additional CSS? Any suggestions on achieving this natively? Appreciate your help. ...