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

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...

fixed width div with width proportion

experts. I'm currently experimenting with a spinning cube effect for my gallery and I recently came across Paul Hayes' experimental cube on his website (it's best viewed in Google Chrome). However, I am facing a challenge in getting it to w ...

Is there a more effective method for concealing arrows while scrolling?

I'm attempting to conceal the arrow that appears above the selected header, as depicted below. https://i.stack.imgur.com/wyxdF.png While scrolling, I aim to hide the arrow that appears on the header Company, especially when the first column is sticky ...

How can HTML output be automatically indented?

Seeking a way to automatically indent the HTML generated by my PHP script. I currently use HTML Purifier for validating internal textbox inputs, but I have reservations about using HTML Tidy due to its lack of active development and numerous reported bugs ...

Ways to make <li> elements display inline with React Bootstrap Rows and Columns

I have some content that I need to format and display in a horizontal list. When I only use HTML elements in the list, it appears horizontally as expected. However, when I incorporate React Bootstrap grid layout components like Row and Column, the list dis ...

Steps for incorporating HTML templates into a Next.js 13 project

Looking for advice on converting an HTML template using Bootstrap or Tailwind CSS into a Next.js 13.4 project. I have experience with Next.js 12 but understand that the project structure has changed, removing files like _app.js and _document.js. Any tips o ...

JavaScript and HTML are commonly used programming languages for developing

By utilizing JavaScript, I was able to generate a table dynamically based on user input. For example, if the user enters 3 and clicks "go", a table with 3 rows is created. Using the .keyup function allowed me to target a column successfully. However, an i ...

Flexbox causing issues with relative positioning at the bottom of the screen in various browsers

My flex component looks like this: <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ... width="100%" height="100%" creationComplete="init()"> ....... <components:Naviga ...

How can I determine the width of a Bootstrap Column on a smartphone?

Currently, I am utilizing Photoshop to design a sequence of Wireframes for a forthcoming eCommerce website. I have a solid grasp on Bootstrap functioning based on a '12 column' structure, where the width of each column varies depending on the vi ...

What is the best way to resize a div located below a dynamic div in order to occupy the available space?

My website has a dynamic div1 and a scrollable table inside div2. I need the div2 to take up the remaining height of the window, while ensuring all divs remain responsive. I've tried using JavaScript to calculate and adjust the heights on window loa ...

Develop a reusable block of Vue template when creating a new component

There are times when I find myself needing to repeat certain sections of HTML code in my Template just to keep it DRY. However, creating a new component and passing multiple props and dynamic data seems like too much work. Is there a simpler way to define ...

What is the strategy to load a div exclusively when triggered by a click event, instead of loading it

Can anyone assist me with a problem I am facing on my scripting page? I am currently working on a website that showcases properties. I would like to know how to prevent a specific div from loading when the page initially loads, and instead have its content ...

A common inquiry: how can one pinpoint a location within an irregular figure?

I have been studying Html5 Canvas for a few weeks now, and the challenge mentioned above has puzzled me for quite some time. An irregular shape could be a circle, rectangle, ellipse, polygon, or a path constructed by various lines and bezier curves... I ...

Having trouble fetching information from form in a basic node.js program

Hey, so I'm not exactly a pro at backend development, but I gave it a shot and came up with this straightforward program: Here's my HTML file: <!DOCTYPE html> <head></head> <body> <form action = "http://lo ...

utilize dynamic variables in post-css with javascript

Question: Is it possible to dynamically set or change variables from JavaScript in post-css? I have a react component with CSS3 animations, and I want to set dynamic delays for each animation individually within each component. I've found a similar s ...

The top margin is experiencing issues and is not functioning correctly

I'm struggling to identify the problem with this script: http://jsfiddle.net/AKB3d/ #second { margin-top:50px; ... } My goal is to have the yellow box positioned 50px below the top border of the right box. However, every time I add margin-top to ...

Contact Form Appears to Be Functioning Properly, Yet Emails Are Not Being Received (HTML5 & PHP)

Hello everyone, I need some assistance with creating a contact form. This is my first time working on this, and I am facing an issue. I am using HTML5, which I have some knowledge of, and PHP, which I am not very familiar with. When I try to test the form ...

center items alignment with hidden tags

I'm currently facing an issue with the CSS property display: flex, align-items: center Here is a snippet of my HTML and CSS files: * { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Kumbh Sans', sans-serif; } .na ...

Animating an image in an HTML document by clicking a button through jQuery

I am trying to figure out how to make an image move from the left to the right of a page when a button is clicked. I thought the code below would work, but unfortunately, it's not functioning as expected. I'm new to JQuery and could use some guid ...

Update cursor when hovering over a button

What can I do to make the cursor change to a hand when hovering over my submit button? Currently, the cursor remains as the standard arrow and does not switch when placed on the button. The code for my button is: <button>Submit</button> ...