Menu with a sidebar that conceals dropdowns with scroll bars

I am struggling with a sidebar menu that includes dropdowns and a lengthy list requiring a scroll bar.

The challenge I am facing is that either the scrollbar is positioned off the screen, or the dropdowns are hidden due to the overflow: hidden; property being set.

Below is my CSS code:

/* I want dropdowns to be on the left */
 .dropdown-menu {
    top: 0;
    left: -160px;
}
#rightbar {
    position: fixed;
    right: 0;
    height: 100%;
    background: lightgray;
    width: 300px;
}
/* Usually you would do this, but it hides the dropdown; additionally, the scrollbar is positioned off-screen */
 #wrap {
    height:100%;
    overflow:hidden;
}
#bottomStuff {
    height: 100%;
    overflow-y: auto;
}

https://jsfiddle.net/cp0fqyt9/

Is there a way to make dropdowns and scrollbars functional in a fixed-position sidebar layout without using JavaScript?

Answer №1

The issue arises from the declaration #bottomStuff { height: 100% }. While height: 100% typically represents the full viewport height, in this case, because of the presence of #topStuff and hr, the element #bottomStuff is pushed down beyond the visible viewport area.

(To put it simply, if your browser window is 500px tall, and assuming that #topStuff takes up 100px, only 400px of #bottomStuff will be within the viewport. The remaining 100px extends below the viewport due to the fixed positioning.)

If you are working with browsers that support CSS3’s calc() function (You can confirm compatibility at http://caniuse.com/#search=calc), you can adjust the height like so:

#bottomStuff {
    height: calc(100% - 200px); /* Adjust based on the total height of #topStuff + hr */
}

For a live demonstration, check out this link: https://jsfiddle.net/jonsuh/xo1z0yyg/

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

Challenging design with CSS shapes

Can this specific shape be created using just one HTML element? I am looking to use it for image cropping purposes, so having only one element would make the process easier ...

Ways to apply a box shadow exclusively to specific elements

Is there a way to apply a box-shadow to a div without it affecting specific other divs? In simpler terms, is it possible to prevent shadows from being cast on a particular div? Take for example this scenario: http://jsfiddle.net/Cd6fE/ How can I prevent ...

Create a line with elements that end on the next line without taking up the full width

In a row of three links, I want the third one to be on the next line, but using .new-line { display:block; } makes the link 100% width on the next line, causing the entire area to be clickable. I also have content in the :before that should appear inline w ...

The alignment of input boxes is off

Apologies for the somewhat vague title, I struggled to come up with a more accurate description of my issue. Here is a basic HTML form: <html> <FIELDSET> <DIV> <SPAN class="label">Label 1</SPAN> <DIV ...

Show the table within the flex container

I have a question about CSS. Is it possible to apply display: table to a flex item? Whenever I try to do this, the layout doesn't behave as expected - specifically, the second flex item does not fill the available vertical/horizontal space. .conta ...

Raising css properties using jquery

Is there a way to adjust CSS values using jQuery? I am looking to specifically increase values like top and left, but my current attempt is not producing the desired outcome: var left = 5; $(.object).css("left" + 5); The challenge I am facing is that I ...

Mathematics - Determined the dimensions of an adjusted image size

Currently, I am implementing a basic mathematical method to crop an image. My approach involves utilizing the jQuery plugin called imageareaselect.js to overlay an adjustable layer on top of an image. By resizing this layer with the cursor and clicking a b ...

Calculation of image size in JQuery fails to function properly on Chrome and Safari browsers

CONCEPT This page features a combination of visible and hidden div elements, with the hidden ones becoming visible upon clicking a specific span element. One of these hidden elements contains multiple images with overlaid text that are randomly positioned ...

Utilizing CSS grid layouts to ensure images expand to fit the dimensions of the designated column and

I am currently working with a CSS grid layout that is displaying as follows: .image__gallery-grid { max-height: none; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 2.5rem; dis ...

Is it possible to display ui-router nested views side by side on a webpage?

In my Angular app, I am using ui-router for navigation and implementing nested states/views in a hierarchical manner. Here is how the structure looks: <!-- index.html --> <h1>Page Title</h1> <ui-view></ui-view> <!-- Page1 ...

I must generate numerous copies of my CSS class using JavaScript

My CSS includes a base class named "toast" that contains basic styling, along with a JavaScript function that generates different types of toasts based on user input. The function modifies the toast class by inserting icons and text as demonstrated below: ...

CSS files loaded from an external source onto Google Chrome browser are not being properly

There seems to be an issue with my external CSS style not reflecting in Chrome, even though it is downloaded. When I manually change the stylesheet inline, it works but not otherwise. Interestingly, it functions fine in the Firefox browser. Here is how I ...

Position the Button in the Center between Borders using CSS and MUI

I'm trying to center a button just like the one shown in the image below. It needs to be perfectly aligned with the lines. What is the best way to achieve this? Check out the example on Codesandbox https://i.sstatic.net/dnhKx.png <MainContainer&g ...

Display interactive content according to radio button selection

I have 4 boxes, labeled a,b,c,d. When the user selects box a, specific content should be loaded: If image a is picked, load content 1 If image b is picked, load content 2 If image c is picked, load content 3 If image d is picked, load content 4 I want ...

Error message: The function $(...).tooltip is not recognized when utilizing Bootstrap 4 in npm webpack

I'm having trouble getting tooltips to work in Bootstrap 4 using npm webpack. Here are the node vendors I've installed... $ npm install jquery $ npm install bootstrap $ npm install popper.js --save This is how I am requiring vendors... global ...

Utilize the ::before pseudo-element exclusively for the initial node

Here is the text I need to generate : https://i.sstatic.net/HzKP9.png This represents my HTML code : <!DOCTYPE html> <head> <meta charset="utf-8"/> <link rel="stylesheet" href="style5.css"> <title& ...

What methods can I employ in CSS to adjust my grid template to fit within a column?

My CSS code defines how images appear on my website. Below is my HTML code which displays a list of cars but also includes a component called Car with additional code. <section className="Carslist"> <div className="Carslist-center"> ...

CSS layout with percentage values breaks when viewed on iPad

Currently, I am in the process of developing a website according to a client's requirements. The site works perfectly on OSX Safari, Firefox, and Chrome but has not been tested on PC yet. However, it breaks quickly when accessed on an iPad and is comp ...

SSL page on Wordpress struggles to load CSS files

My current website is on WordPress: The issue I am facing is on this particular page: , where the CSS is not loading correctly. This specific page uses SSL connection, and when checking through Firebug, I noticed that no CSS files are being sent. What co ...

How can we adjust the flex values to ensure the label displays properly on a narrow container width?

The labels in the left column of the form are initially sized correctly, but shrink when there is not enough room. However, there's a discrepancy in label size between rows with 2 items and rows with 3 items. body { font-family: Arial; font-siz ...