Creating Flexible Designs - Implementing a responsive sidebar with dynamic scrolling

I am in the process of developing a simple web application that features a sidebar whose vertical size is dependent on the number of elements it contains.

My goal is to make the web app responsive, ensuring it works well on devices of any size.

In cases where the user reduces the viewport vertically and some elements within the sidebar exceed the viewport boundaries, my objective is for the sidebar to shrink instead of overflowing the viewport. This would allow users to scroll through its contents.

The height of the sidebar is not fixed (e.g., 50% or 700px) as it varies based on the number of elements within it (which could be anywhere from 3 to 30).

To help illustrate what I am trying to achieve, you can refer to the image below:

CSS example

White: represents the viewport

Light Blue: represents the sidebar

Dark Blue: symbolizes the elements within the sidebar

Grey: indicates the presence of the scrollbar

I have managed to implement this functionality successfully when the sidebar has a predefined height using overflow: auto. However, I am facing challenges in achieving the same outcome when the height of the sidebar isn't defined, allowing the child elements to determine its height.

Any assistance on this matter would be highly appreciated!

Answer №1

If my understanding is correct, you have the option to utilize the calc() function in your CSS.

For example: If you want to display 5 elements within the viewport (height), you can implement the following code for styling the elements:

height: calc(100vh/5)

This code essentially means: Divide the total visible height by 5.

For more information, check out this example: https://jsfiddle.net/uniak/rgzf9nmy/

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 scroll function is executed only one time

I'm currently working on implementing a sticky sidebar snippet using jQuery. However, I am facing an issue where the function within .scroll() is only executing once instead of on every scroll event. Can anyone help me identify what I might be doing i ...

transitioning from font-awesome v4 to the latest version, v5

For a while now, I have been utilizing a responsive template. However, I am interested in updating its fa-module from v4 to v5. By downloading the free web package, replacing "font-awesome.min.css" with "all.min.css", and adjusting all references to the ...

Troubleshooting in Next.js 13: Issue with module not being found while trying to reference a package containing CSS

Currently working with Next.js version 13.4.2 and I have included an npm package that comes with CSS styles and fonts. The issue arises when trying to utilize one of the CSS files within my application. In the layout.tsx file, I imported the CSS file as fo ...

Is it possible to apply identical css styles to multiple ids at once?

Is there a way to accomplish this? .apple, .orange, .kiwi h1 {color: #892828;} I'm having trouble making it work. Any suggestions? ...

The content at the center of the page is shifting to the right side when the browser is resized

I am currently working on creating a random quote generator at the following link: http://codepen.io/Kestvir/pen/peqjZZ. During the html/css aspect of the project, I have run into an issue with the content inside a transparent background. Whenever I resi ...

Hiding the SVG element with pattern definitions using the 'display: none' property makes the patterns completely disappear from view

When I include a set of SVG definitions at the top of my body, I encounter an issue where the svg tag with zero height and width creates unnecessary space at the beginning of the document. To resolve this, I initially use display:none, but this leads to pr ...

Include a hyperlink to a website that was created with the help of Photoshop

Is it feasible to incorporate a hyperlink into a website that was designed using Photoshop templates? In the past, creating templates in Photoshop and then adding links with tools like Dreamweaver was common practice. I believed that dynamically adding li ...

How can the value of a button be displayed in an input box using an onclick function?

When the button '1' is clicked, it displays the value "1" inside a <!p> tag. However, the second button '2' does not display the value "2" in the input box. Even though both functions are identical. //Function with working func ...

What is the best way to send multiple responses from an Express server using res.write and execute a specific action after each write operation?

I currently have an active express server that is sending data using res.write() Fetcher.js function fetcher() { console.log("fetcher function called") fetch('/units.html', { method: "POST", body: JSO ...

What could be causing the issue with the width: 100% not rendering correctly in this

I'm currently working on my footer, but I'm having trouble getting the width: 100% tag to work correctly. Here's a screenshot of what I mean: http://gyazo.com/9c23897cd7b9a74ca55ee9fb977f810c This is my CSS code: /*..Portfolio - Lars Beut ...

Interact with an external JavaScript function using a button within a web application

I have a JavaScript file called dmreboot_service.js in my /js folder. By running this file with the command node /js/dmreboot_service.js, it successfully triggers a direct method in Azure. My goal is to be able to run this function or file when a button o ...

Retrieving the chosen option in Vue.js when the @change event occurs

I have a dropdown menu and I want to perform different actions depending on the selected option. I am using a separate vue.html and TypeScript file. Here is my code snippet: <select name="LeaveType" @change="onChange()" class="f ...

Passing an undefined value to the database via AJAX upon clicking a button

Hi there, I'm currently working on a table where I'm trying to perform an inline edit and update the value in the database by clicking on a button (an image). I've attempted to use an onclick function, but it seems to show "value=undefined&a ...

The variable in the HTML input value is not fully visible when filling out the HTML form

I am working with a Python Flask code where I have passed a dictionary to an HTML form. The table in the form correctly displays both keys and values, but when trying to populate a form field with the value from the dictionary, only the first word is displ ...

Connect an existing function to JQuery animation

There is a function in place that changes the background image of a vertical website when a navigation menu item is clicked. <script type="text/javascript"> $(function() { $('a.panel-home').click(function(){ $("#bgimg").attr(' ...

Ensure the webpage is set to have a minimum width of 1024 pixels

Is it possible to make a webpage that utilizes bootstrap, Angular 2x, and Scss stop being responsive once the screen width reaches 1024px? I would like the layout to stay fixed at this size and enable horizontal scrolling for users who resize their browser ...

Creating a Parent Container to Maintain the Height of the Tallest Offspring

I've been searching online for solutions, but so far I haven't found one that meets all the requirements. <div class="parent"> <div class="child1">I am 60px tall and always visible; my parent is 100px tall</div> <div ...

Why do my tablet media queries take precedence over mobile view media queries?

I've noticed that when I view my website on mobile devices, the tablet media queries always seem to override my mobile media queries. Can anyone explain why this is happening? Here is how I have set it up: /* X-Small devices (portrait phones, less t ...

Ways to tidy HTML/XML code?

Upon receiving a web service response, the data appears as such: <text>&lt;span class="TitleServiceChange" &gt;Service Change&lt;/span&gt; &lt;span class="DateStyle"&gt; &amp;nbsp;Poste ...

Interactive Geography Selector

When updating your personal details on , you are required to choose your country first. Once the country is selected, the system automatically adjusts the city and/or state options based on that specific country's requirements. Can someone provide exa ...