Issues with the background-image scroll feature not functioning as intended

Can anyone help me out with a CSS issue I'm having? I've set an image as my background on a webpage and I want it to scroll with the page. Even though I followed some online tutorials, it's still not working for me. It's been a while since I worked with Html/CSS, so any assistance would be greatly appreciated. Thanks!

header.masthead::after {
  content: "";
  background-image: url(/assets/img/gradient-bg.jpg);
  /* background-image: linear-gradient(-20deg, #2b5876 0%, #4e4376 100%);
  background-repeat: no-repeat;
  background-position: right top;
  background-attachment: scroll;

  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: fixed;
  z-index: -1;
}

<header class="masthead">
        <div class="container">
            <h1 id="mainH1" class="mastshead-subheading" style="color: white" ;>Find ideal <span
                    style="font-weight: 700;color: rgb(140,113,255);">mouse</span> for your hand</h1>
            <h2 class="mastshead-subheading" style="font-weight: 700;color: rgb(140,113,255);"> Select your screen
                <button type="button" class="btn btn-primary" style="font-weight: 700; font-size: 2rem;"
                    data-container="body" data-toggle="popover" data-placement="top" data-content="Diagonal should be written in info box on back side of your computer screen.
                    Google model of your monitor (written on back side of your computer screen).
                    Measure it with ruler (1 inch = 2.54 cm).">diagonal<sup> ?</sup></button> in inches
            </h2>
            <div class="text text-white"
                style="display:inline-block;background:transparent;border:none;font-weight:600;font-size:1.15rem;margin:0;"
                role="alert">
                <u>Make sure that your browser zoom is set to 100%</u>
            </div>
            <div id="inches-wrapper">
                <select id="inches" class="selectpicker" title="''" data-style="btn-warning" data-dropup-auto="false"
                    data-display="static" style="color:grey !important; font-size: 50px;">
                </select>
                <div id="manual-inches-wrapper">
                    <input id="manual-inches" placeholder="''" autocomplete="off">
                    <br>
                    <button class="btn btn-lg btn-dark" id="inches-confirm">OK</button>
                    <br>
                    <div class="alert" id=alert>Wrong input</div>
                </div>
                <!--
                <div class="bubble" id="firstBubble">
                    <img class="bubble-img" src="assets/img/step1-2.png">
                </div>
                -->
            </div>
            <!-- js-scroll-trigger in js code-->
        </div>
    </header>

Answer №1

To make the image work, simply move it to a separate dive.

<header>....</header>
<div class="background-image"></div>

header{
  height:200vh;
}

.background-image {
  content: "";
   background-image: url(https://m.media-amazon.com/images/M/MV5BZTI2YTlhMWMtNWY1Mi00NGQ3LWFkMjEtZjI3NmUzYjI1NWFmXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_.jpg); 
/* background-image: linear-gradient(-20deg, #2b5876 0%, #4e4376 100%);*/
  background-repeat: no-repeat;
  background-position: right top;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: fixed;
  z-index: -1;
}

I adjusted the header height to be twice the view height in order to require a scroll bar.

https://codepen.io/shaniemoonlight/pen/WNoQOXj

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 Bootstrap 5 Accordion Content is not Showing Up

In my current project in vscode, I am using Bootstrap 5 to develop a website. Specifically, I am working on creating an accordion feature with Bootstrap 5. However, I encountered an issue where the accordion body does not show up when clicking on the acc ...

Switching up the size of individual components in the Bootstrap grid system: The ultimate guide

Is it possible to adjust the width of specific elements in Bootstrap's grid system without affecting the default customization? Here is an example of what I am referring to: For example, I would like to make col-xs-1 smaller as seen in the top row ( ...

The background image is being cropped outside the item. What steps should I take to display it properly?

I am facing an issue with positioning a background image just outside the lime container. When I position it correctly, any part of the image that extends beyond the container gets cut off. How can I display the whole image even if it is outside the conta ...

Tips to ensure the div remains 100vh in height, even when empty

As I work on a simple webpage with a header, body, and footer, it's essential for me to ensure that the content takes up the entire height of the page using 100vh. However, if I only have plain text in the body section without any child tags, it ends ...

Set the dropdown item as selected using AngularJS

I have created a demo of an AngularJS dropdown menu, and it's working perfectly. Now, I want to make the selected item appear active. I'm not sure how to achieve this. Can anyone please assist me? I am using the Angular-Dropdown.js library. Here ...

Rotate Chevron icon downwards on mobile devices in a Multilevel Dropdown Bootstrap 4

Bootstrap 4 is being utilized for my current project, I am looking to modify the rotation of the chevron icon in a multi-level dropdown menu specifically on mobile devices when the parent link is tapped, Here is the code snippet for the multi-level dropd ...

Having an issue with displaying the country name and country code in a table using the Angular7 custom pipe

country code: "ab", "aa", "fr", ... I need to create a custom pipe that will convert a countryCode into a countryName, such as: "ab" → "Abkhazian", "ch" → "Chinese", "fr" ...

Is it possible to continuously generate webpages using AJAX?

Is there a way to achieve an infinite scrolling effect in all directions using ajax requests without the need for flash or silverlight? If anyone has an example of this, I would love to see it! Thank you for your time. ...

Utilizing browser local storage in web development

Currently, I am in the midst of working on an e-commerce platform, a project that holds significant importance for me as it marks my debut into major projects. For the first time, I am delving into the realm of local storage to manage basket data such as q ...

Prevent draggable functionality of jQuery UI on elements with a specific class

I have created a dynamic cart feature where users can drag and drop items into the cart. However, once an item is placed in the cart, it should no longer be draggable (though still visible but faded). I attempted to achieve this by using the following code ...

Designing a carousel-style menu list with navigation buttons for moving forward and backward

I'm running into some trouble while attempting to create a carousel. Firstly, the issue I am facing is that when you continuously click on the Next button, the function keeps working even after reaching the last item. I'm not sure how to make th ...

A full-width div containing a child span is unable to be aligned to the right

After reviewing this fiddle, I'm struggling to get my menu aligned correctly at the right edge of the overall "card". Despite trying various methods like margins, right: 0, and float, nothing seems to work as expected. In some cases, I even end up los ...

Is there a way for me to have a background image behave like an img element with img-fluid class as shown in the

Showing 2 rows The issue lies with the first row, as it is not displaying properly and does not resize responsively like the second row. I have tried everything but nothing seems to work. I am attempting to do this because the text and elements in the ...

Centering loaders within elements of an unordered list

I am working on a navbar that uses Bootstrap 3 and AngularJS. Within this navbar, I have an unordered list with li elements. Below is a snippet of my navbar: https://i.stack.imgur.com/o75Lp.png This is the code for my navbar: <div class="navbar-head ...

How to activate a media query in response to user interaction using JavaScript

My responsive web page has various designs for different screen sizes, implemented using @media queries. I am interested in allowing users to manually adjust the design for smaller or larger screens without actually changing the screen size. Is there a wa ...

Having trouble getting rounded-lg and rounded-md to work properly with Tailwind CSS - any ideas why?

I'm currently working with Next.js version 14.2.4 and tailwindcss version 3.4.1, and I've encountered an issue where rounded-lg and rounded-md classes are not applying any border radius. Oddly enough, other classes like rounded-xl and just rounde ...

Is it possible to apply a PNG icon collection using CSS?

Throughout various examples, jQuery plugins, and CSS-styled HTMLElements, I have observed the setting of icons on an image with multiple options. I am eager to implement this practice in my own apps. https://i.sstatic.net/WDCH3.png For instance, in the ...

Loading images with CSS media queries is an essential technique for optimizing

Currently, I am exploring options to dynamically load a background image based on the width of the browser window. This way, I can optimize bandwidth usage by only loading the image that will be displayed. I am aware that using the HTML picture tag allows ...

CSS transformation: skewing without any blurring effects

Is there a way to create tilted drivers with borders and text without sacrificing the sharpness of the font and border? I have used the transform: skew(); CSS rule for tilting, but it has caused blurriness. How can I add font smoothing and maintain sharp b ...

Utilizing HTML5 Drag and Drop feature to track the initial position of the element being dragged

Currently, I am utilizing the HTML 5 Drag and Drop API to create a sortable list with auto scroll functionality. One crucial aspect I am trying to incorporate is the ability to detect which specific part of an element was grabbed by the user. Take a look ...