The sidebar's background is cut off before reaching the bottom when scrolling

I have been working on creating a sidebar that includes a background image with a transparent overlay. However, I encountered an issue where the overlay background does not stretch all the way to the bottom when the scroll bar becomes visible. Despite setting the height to 100%, it doesn't seem to be functioning as expected.

To see this issue in action, you can check out the reproduced fiddle here: https://jsfiddle.net/queeeeenz/7do4wysb/1/

Take a look at the screenshot below:

https://i.stack.imgur.com/4u1uc.png

Here is the HTML and CSS code snippet:

<html>
    <head>
        <style>
            .sidebar {
                position: fixed;
                left: 0px;
                top: 0px;
                background: url('https://images.unsplash.com/photo-1610643748471-2eae4a44bd18?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=675&q=80') center center / cover;
                width: 240px;
                overflow-y: auto;
                height: 100%;
                display: flex;
                flex-direction: column;
                padding: 20px;
            }

            .sidebar::after {
                position: absolute;
                z-index: 1;
                bottom: 0px;
                left: 0px;
                width: 100%;
                height: 100%;
                content: "";
                display: block;
                background: rgb(255, 255, 255);
                opacity: 0.55;
                max-height: 100%;
                min-height: 100%;
            }

            .sidebar__item {
                padding: 20px;
                background: white;
                border-radius: 7px;
                margin: 10px;
            }

            .sidebar__content {
                z-index: 2;
                padding-bottom: 30px;
            }
        </style>
    </head>

    <body>
        <div class="sidebar">
            <div class="sidebar__content">
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
                <div class="sidebar__item">Hello</div>
            </div>
        </div>
    </body>
</html>

Answer №1

To enhance the background, you can simply add an additional layer:

.sidebar {
    position: fixed;
    left: 0px;
    top: 0px;
    background: 
     linear-gradient(rgba(255, 255, 255, 0.55),rgba(255, 255, 255,0.55)),
     url('https://images.unsplash.com/photo-1610643748471-2eae4a44bd18?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=675&q=80') center center / cover;
    width: 240px;
    overflow-y: auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar__item {
    padding: 20px;
    background: white;
    border-radius: 7px;
    margin: 10px;
}

.sidebar__content {
    padding-bottom: 30px;
}
<div class="sidebar">
    <div class="sidebar__content">
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
        <div class="sidebar__item">Hello</div>
    </div>
</div>

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

Concealing overflow for text content through CSS styling

I am currently working with an element that contains both an image and text. View the Fiddle here Note: To see the full grid, resize the preview accordingly. The CSS I have written is as follows: .gridster .gs-w .item{ position: relative; wi ...

Is there a way to verify the content of a span and automatically guide the user elsewhere if it meets certain criteria?

Currently, I am facing an issue with adding Google authentication to my website as the redirect function is not working properly. As a solution, I plan to implement manual redirection using JavaScript in case the value of the span element is <span id= ...

Utilize the href attribute on an image, whether it be through a class

I work as a designer and I'm looking to extract the same href link from class="kt-testimonial-title", either in id="slick-slide10", or in class="kt-testimonial-item-wrap kt-testimonial-item-0", or in class="kt-testimonial-image". Can this be achieved ...

Struggles encountered when choosing the initial visible item

I have a set of 3 tabs, each with its own heading and content. However, I only want to display the tabs that the user selects by checking the corresponding checkboxes. There are 3 checkboxes, one for each tab. Below is the code snippet: //Function to ...

How can I pass an Objective-C object to JavaScript?

Currently, I am working on a UIWebView project that involves HTML and JavaScript. One of my friends is working on something similar but for Android. The challenge I'm facing is that in Android, there is a simple way to send an Android object to JavaS ...

The issue I am facing is that when I click on a checkbox, only one of them seems to respond

When I click the button, only the first checkbox event is being checked while the rest of them are not. Can someone please provide some guidance on how to fix this issue? $("#cascadeChange").click(function() { //alert("Clicked"); ...

Utilizing personalized CSS for specific ioslides

If I decide to stick with the default data and presentation of a new ioslides, changing only the second slide (## R Markdown) without affecting the entire item, how can I do this by setting up the css document accordingly? My goal is to simply adjust the f ...

Employing AJAX to send form data to a pair of destinations

Can anyone help me out? I am having trouble using AJAX to submit my form to one location and then to another. Once it's posted to the second location, I want it to send an email with PHP to a specified recipient, but for some reason, it's not wor ...

Creating a three-column layout with position fixed in the center

I'm struggling with achieving a maximum width of 400px for the entire set of three columns and centering them. ---------------------------------------------------- | | | |----------------------------- ...

Is there a way to incorporate an 'ended' feature into the .animate() function?

I'm currently working on a jQuery statement where I want to activate pointer events once the button animation is finished. However, I'm unsure how to incorporate an ended or complete function. Any suggestions on how to approach this? $('#ce ...

Focus on selecting each label within a table using JavaScript

In my current setup, I am attempting to customize radio buttons and checkboxes. Array.from(document.querySelectorAll("tr")).forEach((tr,index)=>{ var mark=document.createElement("span"); Array.from(tr.querySelectorAll("input")).forEach((inp,index ...

Contact Company by Sending Email According to Selected Product Dropdown Choice

If a customer selects a specific business option from the dropdown menu on the product page, I want to send the standard WooCommerce Order Confirmation Email to both the site admin and that selected business. Backpack $50 Choose an Option Business First ...

Incorporating Dynamic Javascript: A Step-by-Step Guide

I came across a select object that looks like this: <select id="mySelect" onchange = "start()" > <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> < ...

Exploring numerous choices within a multi-select "category" search bar (web scraping)

Looking to scrape data from this French website using Python and the bs4 library: the content is in french :) . Specifically interested in extracting all possible values of a multi-select search bar named 'TYPE DE BIENS'. This type of search bar ...

How to target the following sibling element (not a child) with CSS

I am working with the following HTML structure: <div class="col-sm-12"> <input id="my_id"> <div class="col-sm-1 col-3-box" style="position:absolute; margin-left:340px;"> </div> </div> How can I target and change ...

Text Alignment in a Responsive Design

Is there a way to create a responsive container that automatically centers all items inside it on the page, regardless of the screen size? Thanks :) Images are not included in this code snippet, but here's the code: HTML <!DOCTYPE html> <h ...

How can I create a parent div with cursor-pointer and apply inline styling to make all child elements

Is there a way to apply the cursor-pointer style to an entire div with inline CSS without it affecting just the white space around the child elements? I have tried using position and z-index without success. I am unable to use an external stylesheet for t ...

Display flex behaving unexpectedly in Chrome and Safari browsers

I utilized flexbox properties to achieve this layout for my section: While it functions smoothly in Chrome, I noticed some disparities when viewing in Firefox and Safari. This is how it appears in Chrome: In Firefox, I'm encountering difficulty in ...

PHP script is not successfully receiving the Ajax post request that is

As a newcomer to the world of php and ajax, I am facing a challenge in passing a variable from jquery to a php page loaded within a modal window. My php script fetches table information for multiple users. Next to each user's name, there is an edit b ...

Altering the playback of a flash object using HTML or JavaScript

Can the playback speed of a flash object be adjusted without recompiling the object, like through HTML attributes or JavaScript? Appreciate any help in advance ...