Prevent the sidebar from moving vertically with scrolling

I have a sidebar in my code that I found from this source. The issue I am facing is that when the content on the page becomes too long, the body scrolls but the sidebar remains static.

For reference, you can view an example fiddle here.

While I would like my sidebar to function similarly to the one in the example above, I encounter an unwanted effect due to a header as shown here.

Here's a snippet of the HTML:

<title>Simple Sidebar - Start Bootstrap Template</title>
<body>
    <!--Header-->
    <div id="header-content-wrapper" class="as-header-wrapper">
        <div class="container-fluid">
            <div id="header" class="row">
                <div class="col-md-7 panel">
                    <span>This is heading text!!!</span>
                </div>
            </div>
        </div>
    </div>
    <div id="wrapper" class="">
        <div id="sidebar-wrapper">
            <ul class="sidebar-nav">
                <li class="sidebar-brand"> <a href="#">
                        Start Bootstrap
                    </a>

                </li>
                <li> <a href="#">Dashboard</a>

                </li>
                (other list items here)
            </ul>
        </div>

        <div id="page-content-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                         <h1>Simple Sidebar</h1>

                        (content continues...)
                    </div>
                </div>
            </div>
        </div>
        
    </div>
    
</body>
</html>

And this is the CSS styling related to the sidebar and its behavior:

(CSS code snippet)

My goal is to prevent the sidebar from scrolling along with the content by adjusting the position property in the CSS. Any suggestions or advice on achieving this are highly appreciated!

Answer №1

Some adjustments are needed in the css file ...

#wrapper {
    padding-left: 0;
    overflow-y:none; //NEED TO ADD
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
    max-width:100%;  //NEED TO ADD
}
#wrapper.toggled #page-content-wrapper {
    position: absolute;
    margin-right:-250px; //NEED TO REMOVE
}

UPDATE :

After some testing, this is what you're attempting to achieve : http://jsfiddle.net/DTcHh/4759/

However, there are a few issues with the styling on smaller screens... the menu style seems to change (to white background instead of black) and other problems...

It's mainly related to css "position" and sizes... but this should provide a good starting point.

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

Issue with the display of images

Is there a way to make a pop up image visible when hovering or clicking on an image on the webpage? Currently, the new pop up image is hidden behind the right div. Thank you in advance for any help. Paul ...

Step-by-step guide on installing packages through commands like npm, gulp, and git

I have a question about implementing Uikit Customizer in my website. I am familiar with uikit and its similarities to bootstrap, but the customizer implementation is new to me. The support team suggested following the commands in this link (http://getuikit ...

Tagging photos - Displaying tagged box when hovering over a name

I am currently working on a feature where hovering over a tag name in the list will display a box at the tagged location (similar to Facebook). Below is the code I have: Viewtag.php <?php $sql = "SELECT * FROM image_tag ORDER BY `pic_id`"; $qry = mys ...

The text in the TextArea is not displaying line breaks as expected

Similar Question: Issue with new line preservation in .val() method for textarea I'm facing an issue where my text area does not preserve newlines when I enter a message with multiple lines. Even after retrieving the value from the text area, the ...

The CSS code for adjusting width, text alignment, and margin for the <a> tag is not functioning correctly

Currently, I am only able to get color, padding, and font codes to work in my HTML. When I attempt to add width or align the text to the right, it does not seem to work. <a href="https://www.football.london/chelsea-fc/transfer-news/juventus-chelsea ...

Creating a server-side HTML template: A step-by-step guide

I need to create a consistent layout for all of my website pages using Bootstrap. While I already have a layout designed for a single page, I want to apply the same design across all pages. My initial thought was to utilize Jade for this task, but I want t ...

Encountering the error message "Uncaught TypeError: $.ajax is undefined"

Recently, I encountered an issue with my form that utilizes ajax to send user information to a php file. The form is embedded within a bootstrap modal and was functioning perfectly until I attempted to add an extra field for enhanced functionality. However ...

Change the attribute to read-only upon modification of the dropdown value

I have a dropdown menu with four options. My goal is to make the "number" input field readonly if the user selects either "option3" or "option4" from the dropdown. <select id="dropdown"> <option value="option1">option1</option> ...

Trouble with HTML Contact Page Email Delivery

Hello there, I recently set up a contact page for my html website but unfortunately, it's not sending the messages to my email as expected! You can see what I mean in this screenshot -> https://i.stack.imgur.com/2xPXw.png I'm a bit puzzled b ...

Automated scrolling within a div when an li element overflows

Looking to implement automatic scrolling in a div. I have a list of elements within a fixed height div, and now I want the div to scroll automatically when I press the down key after highlighting the 3rd li element (i.e Compt0005). Can anyone help me solve ...

Tips for hiding navigation items on mobile screens

I've been learning how to create a hamburger menu for mobile devices. Within a navigation structure, I have three components: Logo, nav-items, and hamburger menu. Utilizing flexbox, I arranged them side by side and initially hid the hamburger menu on ...

Having trouble accessing CSS images in JSF

Issue Details : I am currently facing a problem with setting menu background images in my JSF application using CSS properties. The file structure is as follows This is the CSS snippet Style.css #menu { height:35px; width:950px; backgrou ...

What is the best way to add padding or margins to the heading that is being shown as a table-cell?

After finding an example for a header with lines on the side (source here, specifically: here), I've managed to implement it successfully. However, I am facing a challenge when trying to add some padding to both sides of the text and having the lines ...

Identifying the method of navigation using PerformanceNavigationTiming

Previously, I was able to determine if a user had arrived on the page by clicking the back button in the previous page using window.performance.navigation.type like this: if (window.performance.navigation.type === 2) { window.location.reload() } Howe ...

The issue with Angular JS is that it fails to refresh the select and input fields after selecting a date

Currently utilizing Angular JS and Bootstrap, I have a query regarding updating the input for a datepicker calendar and a select from a function. The values are being successfully updated, however, they do not reflect on their respective inputs. It seems ...

What is the best way to choose CSS class attributes using Mootools and the getStyle()

Seeking to duplicate an object, I am trying to figure out how to retrieve class CSS attributes from Mootools. css: .card { width: 109px; height: 145px; } html: <div id="cards"> <div class="card" id="c0"> <div class="face fron ...

Inequality in spacing between Bootstrap columns

I am currently working on a website where the home page has columns with icons and text. The issue arises on mobile devices as the columns stack unevenly due to varying text lengths, resulting in inconsistent vertical spacing. Is there a way to ensure cons ...

What is the best way to choose a tab while modifying a chosen option?

Is there a way in Bootstrap 4 to have tabs switch based on the selection from a dropdown menu? <ul class="nav nav-tabs" id="myTab" role="tablist"> <li class="nav-item"> <a class="nav-link active" id="home-tab" data-toggle="tab" href ...

How to troubleshoot Javascript code that fails to identify if a color is white

What could be causing my code to malfunction? I am attempting to determine if the paragraph text color is white (as determined by CSS settings). If it is indeed white, I want to change it to black for better visibility. function adjustColor() { if (d ...

The CSS styling for an active link is not functioning correctly on a single page when using sections

I recently received a zip file containing a template purchased from themeforest, with a request to make modifications. The template includes a horizontal navigation bar with links to various sections on the page. In the original template, when you click on ...