Creating a fixed header design with a scrolling sidebar using CSS

I'm currently working on establishing the layout of my page by drawing inspiration from this website. Specifically, I aim to have a fixed header/nav-bar with a sidebar that scrolls independently and a content panel that scrolls conventionally. It seems that the site I referenced is utilizing flexbox functionalities, however, I need to cater to older browsers (at least IE8 and above), so I am looking to create this layout using pure CSS or incorporating jQuery.

You can view a demo in this fiddle here, which illustrates the basic structure based on two primary wrappers:

.wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}
.body-wrapper {
    margin-top: 80px;
    width: 100%;
    height: 100%;
}

The issue with my implementation is that the sidebar doesn't scroll independently. Therefore, when the main scroller is used, both the sidebar and body content scroll together, whereas I intend for only the latter to be affected.

Thank you in advance for any help provided; I am open to modifying my current version or exploring an entirely different approach.

Answer №1

If you want to make some adjustments without changing your current approach too much, you can utilize the position:fixed property for the sidebar as well. Simply include these CSS styles:

div#mainBody {
    padding-left:220px; /* Set width of #list */
}
aside#list{
    position:fixed;
}

I renamed the id for the main content container to #mainBody since you already have a #main for the header on your page. IDs should be unique. Take a look at this JSFiddle example.

Hopefully, this explanation is helpful. Feel free to ask if you need further clarification.

UPDATE: The issue with the bottom of the sidebar being cut off is due to the following style:

aside#list {
    height:100%;
}

By setting the height of the sidebar to 100% of the viewport's height, it gets pushed down by the header and goes off-screen, making it unreachable by scrolling. To resolve this, remove that style and use this instead:

aside#list {
    bottom:0;
    top:80px; /* Height of the header */
}

This adjustment ensures the sidebar starts below the header and reaches the bottom of the viewport, allowing all content to be scrolled through. Check out the updated JSFiddle to see the changes in action.

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

Import HTML content into R

In my project, I am trying to use R to extract the pronunciation of each word from a column in a dataset by accessing a specific website. I have started coding for this task as shown below. The goal is to fetch the pronunciation for each word from the we ...

Is your sticky sidebar getting in the way of your footer?

I've developed a custom sticky sidebar for displaying ads, but I'm facing an issue. When I scroll to the bottom of the page, it overlaps with the footer. Can someone please take a look at this? - var stickySidebar = $('.sticky'); if ...

Ways to center elements horizontally without relying on Flexbox layout?

Is there a way to arrange the web elements side by side without relying on Flexbox? Although an effective tool, Flexbox does not function properly with IE 9 or 10. I am aiming for the text inside the link to be displayed immediately next to the images. The ...

custom gradient generator for jquery and css3

Is there a jQuery CSS3 plugin available that can handle cross-browser gradients? I've noticed that most gradient plugins out there involve creating multiple elements. Thank you. Edit: I apologize for any confusion - I'm not attempting to force ...

Displaying Child1 on hover in CSS is simple using the Parent > Child1:hover selector. But how can we display Child2 using

Is there a way to modify my CSS Combo Box to display the menu div when hovering over the button div instead of the dropdown div? I have a container div with a dropdown div containing a button and a hidden menu. Currently, the menu is displayed when hoveri ...

Content misaligned vertically inside a DIV

I'm struggling to understand why the browser is not allowing me to apply margin-top or padding-top to a DIV in order to center the text. HTML - <div id="header"> <div id="Nav"> <div id="navright"> ...

Is there a way to right-align the labels and input fields simultaneously?

Is there a way to line up the labels and inputs on the right side so they all appear in the same row? .radioContainer{ width: fit-content; margin: 5px; margin-top: 20px; background-color: aqua; padding-bottom: 25px; } <div class=" ...

What could be causing a react element to fail to update?

I'm currently working on a React component that interacts with a MaterialUi text form. The component utilizes a useState hook to update based on the input received. My goal is to have another variable update when the form is submitted, which will be d ...

Error: The Jquery plugin Object #<HTMLDocument> does not have a function called 'observe'

Hello, I recently tried to install the Jquery plugin known as chosen that allows customization of my <select> tag across different browsers. If you're interested, you can find more information about it here. However, after integrating this plugi ...

What are the steps to embedding a Facebook video on a website?

Could someone please help me with embedding a Facebook video? I tried following the instructions provided at: https://developers.facebook.com/docs/plugins/embedded-video-player Unfortunately, I'm having trouble getting it to work. Here is the sourc ...

Dealing with a jQuery/JavaScript issue involving thumbnail images

I am facing an issue with smooth transitions between thumbnail images in HTML list tags. I have Jquery listeners set up for mouseenter and mouseleave events that update a parent image when a thumbnail is hovered over. The problem arises when scrolling fro ...

Using the <noscript> tag for an individual element or a comparable alternative

So, I have a link labeled "Impressum" that when clicked, opens up the Impressum section. <a data-open="something">Impressum</a> <div class="reveal" id="something" data-reveal> <img src="images/reverseLogo.png"> <h1>Imp ...

Problem with sending a form using Ajax

I've set up a page that dynamically generates a list of items. Each item in the list includes a button to submit a form with data specific to that item (the sorting is working correctly). The form submission is handled by the following jQuery code: & ...

Each function in Sass is compiled with a dollar sign preceding it

I'm having trouble using an each loop in Sass because the css is compiling with the variable names instead of their content. $green-1: #9ae200; $green-2: #5ea600; $color-list: green-1 green-2; @each $single-color in $color-list { &.#{$single ...

What is causing the links at the bottom of the page to not function properly?

<div class="col-lg-4 col-sm-12 footer-social"> <a href="https://www.facebook.com/unique.page123"><i class="fa fa-facebook"></i></a> <a href="https://twitter.com/UniquePage456"><i class="fa fa-twitter"></ ...

CSS: positioning elements relative to the bottom right corner

The structure of the floating element is as follows: <a>The_button</a> <div style="position:absolute"> <div style="position:relative" class="inner-box"> Content Content Content Content Content ...

Tips for closing a popup without exiting the entire webpage

I'm facing an issue while trying to create a video playlist using two HTML files (index.html and video.html). In my video.html file, I have set up a popup for playing videos. However, whenever I close the popup or click anywhere on the page, it redire ...

Update the class of pagination to "active" using jQuery

I need assistance with pagination. Here's the code I have so far: <?php for($i = 1; $i<=10; $i++){ ?> <a class="pagenumber" href="?p=<?php echo $i; ?>"><?php echo $i; ?></a> <?php } ?> What I want to d ...

Clear function of signature pad not working inside Bootstrap modal dialogue box

Currently, I'm working on implementing a signature pad dialogue box using Bootstrap modal. When the user clicks on the "Complete Activity" button, a dialog box should pop up with options for yes or no. If the user selects yes, another dialog box shoul ...

What is the best way to split an array into four columns and allocate 10 <li> items from the array to each column?

If I have a dynamic array with 40 elements that changes on every render, how can I loop through the array and return 4 groups of elements, each containing 10 items without any repetition? I want to style these objects in the array using a parent flex con ...