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

What is the best way to extend the final column of a table across the entire width?

Here's the code I'm working with: .frm-find-people table td:nth-child(1) { padding: 5px 15px; width: 100px } .frm-find-people table td:nth-child(2) { border: 1px solid red; } <form class="frm-find-people"> <table> ...

Is there a way to customize the CSS for a single blog post and add a 5-star rating system without affecting other posts?

After launching my blog on Google's Blogger, I wanted to add a unique touch by incorporating a static 5-star rating system in my Books I Read Section. I thought about using CSS to customize each book post and display anywhere from 1 to 5 stars for vis ...

Troubleshooting CSS Hover Not Displaying Properly in Angular 14

In the footer class of my HTML, there is a code snippet with chevrons: <div class="link-list"> <div *ngFor="let link of insideLinksLeft | originalOrderKeyValue" class="link"> <a [href]="link.val ...

What is the best way to position a Button on the far right of an MUI AppBar?

I'm struggling to grasp the concept of aligning items in MUI. Here is my code snippet: class SignUpForm extends React.Component { render() { return ( <Button sx={{ justifyContent: "flex-end" }} colo ...

Solve the problem with SCSS at the component level in NextJS

I've decided to transition my regular React app to Next.js. In the past, I would simply import SCSS files using: import from '.componentName.scss' However, now I need to import them using: import style from 'componentName.module.scss ...

Display sub navigation when clicked in WordPress

I currently have the default wordpress menu setup to display sub navigation links on hover, but I am interested in changing it so that the sub navigation only appears when the user clicks on the parent link. You can view my menu here https://jsfiddle.net/f ...

Choose Option 1 in order to proceed with selecting Option 2 and displaying the outcome in the VueJs framework

Looking for help on how to show the text value from multiple related select fields. I want Option 1 to display a list of parent options. Upon selecting an Option 1, it should determine what values are available in Option 2 select field. After selection, ...

How can I hover over multiple cells in a table?

Is there a way to change the color of multiple adjacent cells when hovering over one cell, and can this be done dynamically (so the number of adjacent cells that change color can vary)? Here is the code snippet: I'm using React to create a table wit ...

Text alignment issues cause animation to vanish

Utilizing particles.js, I set up a full-screen particle effect by specifying the animation to be full-screen with height: 100vh;. This worked perfectly as intended. However, when attempting to add text on top of the particle animation and center it vertica ...

Is there a way to horizontally align text in a div using center alignment?

Excuse me for what might seem like a silly question, but I am having trouble figuring this out. Edit: All I want is to horizontally center the text without affecting the image's position. The image should stay aligned with the baseline of the text. ...

Display the div when scrolling downwards beyond 800px

Is there a way to display a hidden section when scrolling down the page, specifically after reaching a point 800px from the top? I currently have an example code that may need some modifications to achieve this desired effect. UPDATE: [Additionally, when ...

How can I loop the keyframe animation across various elements of an SVG file simultaneously?

After creating an animation using CSS and SVG, I am experiencing different parts of it animating in and out. My goal is to have the animation start from the top once it's finished. There are multiple keyframes involved since I'm animating variou ...

The active class consistently adds new menu options without removing the previous ones

I am facing an issue with my menu where the active class does not get added to the new menu item when clicked, despite being removed from the previous item. Below is the code snippet: <div class="row text-center" id="side-menu"> <nav> ...

Exploring the ins and outs of utilizing pseudo selectors with material-ui

I've been attempting to accomplish a simple task. I wanted to toggle the visibility of my <TreeMenu/> component in material UI v1 using pseudo selectors, but for some reason it's not working. Here is the code: CSS: root: { ba ...

React Application not reflecting recent modifications made to class

My current project involves creating a transparent navigation bar that changes its background and text color as the user scrolls. Utilizing TailwindCSS for styling in my React application, I have successfully implemented the functionality. // src/componen ...

Tips for altering the scrolling rate of a container

I am trying to adjust the scroll speed of specific divs among a group of 5 divs. I came across a solution that changes the scroll speed for the entire document: http://jsfiddle.net/36dp03ur/ However, what I really need is a scenario like this: <div i ...

Problem with fetching Grails

I have a table nested within an anchor tag. The table is centered on the page, with each row containing an image. When the page loads, I noticed the following: a) The table initially appears at the top-left corner of the screen. b) As there are multiple v ...

The div element moves to the right as soon as the drop-down menu pops up

Currently, I am facing an issue with aligning an image inside a div that is centered in an outer-wrapper. The outer-wrapper contains a horizontal menu at the top with 5 sub divs displayed inline. I have implemented CSS for a drop-down menu that appears whe ...

angular overlapping collapsing

Currently, I am developing a chat board application where users can leave comments under each post. I am in the process of creating a button that will collapse all the comments for better visibility, especially as they continue to grow. <div id="collap ...

Height CSS does not conceal side bar hyperlinks

CSS .nested-menu { .list-group-item { cursor: pointer; } .nested { list-style-type: none; } ul.submenu { height: 0; } & .expand { ul.submenu { ...