Tips on using css filters on a fixed background image

I am currently working on a website that features a fixed background image with scrollable elements on top. I am facing an issue where applying a grayscale filter to the image also affects the text within the container, turning it gray as well. However, I only want the image to have the grayscale effect, not the text. How can I solve this problem?

Here is the Bootstrap code snippet:

<section id="section-toTheTop"
    class="jumbotron jumbotron-fluid fixed-background d-flex justify-content-center align-items-center">
    <div class="container text-center">
        <h1 class="display-1 text-primary">PHOTOSERVICE</h1>
        <p class="display-4 d-none d-sm-block text-white">Capture every moment</p>
        <p class="lead text-white">Create stunning photos and videos by using the built-in features for enhancement.</p>
        <p class="lead text-white">Share your best shots with your friends and the rest of the world instantly.</p>
        <p><strong class="text-white">Download now on:</strong></p>
        <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-apple"></i> App Store</a>
        <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-google-play"></i> Play Store</a>
     </div>
     </section>

And here is the CSS code snippet:

 .fixed-background {
  background-image: url("img/background.jpg");
  background-size: cover;
  background-attachment: fixed;
  background-position: center;
  min-height: 100vh;
  filter: grayscale(100%);
}

I found a workaround using z-index to solve the issue, as suggested by @Hibrit Usta:

<div class="overlay"></div>
<section id="section-toTheTop"
    class="jumbotron jumbotron-fluid fixed-background d-flex justify-content-center align-items-center">
    <div class="container text-center text-over-image">
        <h1 class="display-1 text-primary">PHOTOSERVICE</h1>
        <p class="display-4 d-none d-sm-block text-white">Capture every moment</p>
        <p class="lead text-white">Create stunning photos and videos by using the built-in features for enhancement.</p>
        <p class="lead text-white">Share your best shots with your friends and the rest of the world instantly.</p>
        <p><strong class="text-white">Download now on:</strong></p>
        <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-apple"></i> App Store</a>
        <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-google-play"></i> Play Store</a>
    </div>
</section>

.fixed-background {
    background-image: url("img/background.jpg");
    background-size: cover;
    background-attachment: fixed;
    background-position: center;
    min-height: 100vh;
}

.overlay {
    position: absolute;
    min-height: 100%;
    min-width: 100%;
    left: 0;
    top: 0;
    background: rgba(0, 0, 0, 0.75);
}

.text-over-image {
    z-index: 0
}

Answer №1

Feel free to test out the following code snippet.

    .background-fixed {
        position: relative;
    }
    
    .background-fixed::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-image: url("https://i.picsum.photos/id/237/1600/1600.jpg");
        background-size: cover;
        background-attachment: fixed;
        background-position: center;
        min-height: 100vh;
        filter: grayscale(100%);
    }
  .background-fixed  .container {
        position: relative;
    }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
    <section id="section-toTheTop"
    class="jumbotron jumbotron-fluid background-fixed d-flex justify-content-center align-items-center">
    <div class="container text-center">
        <h1 class="display-1 text-primary">PHOTOSERVICE</h1>
        <p class="display-4 d-none d-sm-block text-white">Capture every moment</p>
        <p class="lead text-white">Create stunning photos and videos by using the built-in features for enhancement.</p>
        <p class="lead text-white">Share your best shots with your friends and the rest of the world instantly.</p>
        <p><strong class="text-white">Download now on:</strong></p>
        <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-apple"></i> App Store</a>
        <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-google-play"></i> Play Store</a>
     </div>
     </section>

Alternatively, you can consider this approach:

    .bg-image-fixed {
        background-image: url("https://i.picsum.photos/id/237/1600/1600.jpg");
        background-size: cover;
        background-attachment: fixed;
        background-position: center;
        min-height: 100vh;
        filter: grayscale(100%);
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: -99;
    }
    
    .jumbotron {
        background-color: transparent!important;
    }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
  <section class="bg-image-fixed">

    </section>

    <section id="section-toTheTop" class="jumbotron jumbotron-fluid background-fixed d-flex justify-content-center align-items-center">
        <div class="container text-center">
            <h1 class="display-1 text-primary">PHOTOSERVICE</h1>
            <p class="display-4 d-none d-sm-block text-white">Capture every moment</p>
            <p class="lead text-white">Create stunning photos and videos by using the built-in features for enhancement.</p>
            <p class="lead text-white">Share your best shots with your friends and the rest of the world instantly.</p>
            <p><strong class="text-white">Download now on:</strong></p>
            <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-apple"></i> App Store</a>
            <a href="#" class="btn btn-primary btn-lg"><i class="fab fa-fw fa-google-play"></i> Play Store</a>
        </div>
    </section>

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

Retrieve text from an element using jQuery when triggering "mouseenter" on a different element

Is there a way to retrieve the text from an element while simultaneously triggering a 'hover' action on another element? Here is an illustration: I am trying to gather all available colors, but the color names are only visible upon hovering ove ...

Enhance the usability of input-group-addon elements in Bootstrap by incorporating focus and validation states, rather than focusing

When using Bootstrap, focusing on an input activates a blue border and box shadow to show where the user's attention is. If there are validation states such as error, warning, or success, a red, yellow, or green border will be added accordingly. An ...

What is the best way to center two items within a border?

Here is the CSS code I wrote to center align my text with a bottom border: .arrow-down { width: 2rem; display: inline; position: absolute; top: -0.6rem; left: 50%; margin-left: -59px; background: $grey_200; z-index: 5; } .showless > se ...

What is the method for shifting content as the window is resized to ensure it remains in its original position?

My page features a grid with three div elements. Each div is the size of the viewport, resulting in only one div being visible at a time, while the other two remain outside the view. This makes the grid three times larger than the viewport. When resizing ...

Dynamic layout problem with navigation pills

I currently have 2 navigation pill buttons designed to alter the layout upon being clicked. Both layouts always include the sidebar which remains constant throughout. Clicking on Nav pill 1 will display the layout as follows: sidebar | column 1 | column ...

Trigger fixed element to appear/disappear when scrolling using JavaScript

I've tried multiple solutions, but I can't seem to get this functionality to work properly on my website. I'm attempting to create a "schedule a demo" button similar to the one on www.bamboohr.com Currently, I have the following html, css, ...

No matter how much I try, the text refuses to align with the top-left corner

I have been working on creating a loading screen, but I am facing an issue with aligning the h1 tag selected to the top left. As a young developer at the age of 13, I am quite confused. I attempted to use the following CSS properties: vertical-align: top; ...

Automatic scrolling feature in JavaFX

I am currently working on developing a chat box using JavaFX. My goal is to implement an auto-scroll feature that will scroll down the page when it gets filled up. However, I am facing some issues with this functionality. import javafx.application.Applica ...

CSS - Adjusting width based on height ratio

I'm in the process of developing a website and could use some guidance. I have a specific section where I am aiming for the height to be 79.6% of the body, with the width of that div being dependent on its height. Thus far, my research has only yielde ...

Are you looking for a demonstration of "Creative Loading Effects" that triggers when the page is loaded?

I came across this demo for a preloader on my website called Creative Loading Effects, specifically the "3D Bar Bottom" effect, which I find very exciting. However, I noticed that it only loads when we press the button, and not automatically when the page ...

Tips for deleting an additional empty line while styling a <ul> bulleted list?

I'm working on creating a vertical menu positioned on the left side of the screen. To achieve this, I utilized an online CSS button generator to style my <li> tags within the menu structure. However, I've encountered an issue where an extra ...

Safari keyframe animation causing wobbly off-center rotation

When viewed on Safari, the spinning animation appears off-center. How can this issue be resolved? The CSS code responsible for the animation is as follows: html, body { height: 100%; } body { background: #a6b8b1; display: grid; place ...

Getting rid of the outline on <html> while tabbing in Firefox

An odd outline keeps appearing as I tab through elements on a website, but only in Firefox and not in Chrome, Safari, or Opera. To identify the element causing the focus, I used Firebug console by typing: document.activeElement. It showed: >>> d ...

Trouble with Bootstrap accordion staying open even after a different one is chosen

Looking for assistance! I am encountering an issue with using jQuery on Bootstrap. The accordion feature is not functioning correctly as it fails to collapse when another section is selected. https://i.stack.imgur.com/uiZPh.png The problem arises when th ...

Having trouble with CSS media queries not functioning properly on Internet Explorer version 9?

Incorporated media queries in my design to adjust the width of certain elements on the page according to the browser's width. These are the queries I am using: @media screen and (min-width:1024px) @media screen and (max-width:1024px) Chrome, Safari, ...

additional dark border streak

When you resize the browser window, you will notice a different layout for iPhone. I am seeing an additional black line below the slider and I'm unsure how to remove it. I have already tried removing the border property but the black line remains. Bel ...

The menu seems to be off-center

I'm struggling to center my menu/navigation bar horizontally. I can't seem to figure out what mistake I've made or what I've forgotten. Additionally, there is right padding after my last list item. How can I get rid of it? HTML <di ...

Angular 9 - Auto-adjust the height of the text box as the user types, returning to its original size when no longer in focus

I need a solution where an input field's height adjusts to display the user's entry, then returns to normal size when they click away. It should function similar to this example image: https://i.stack.imgur.com/yKcik.png Once the user enters th ...

Layer one image on top of another using z-index

I'm having trouble layering one image on top of another in my code. Here is my code: body { background: #000000 50% 50%; height: 100% width:100%; overflow-x: hidden; overflow-y: hidden; } .neer { z-index: 100; position: absolute; } ...

Line breaking by syllables using CSS

When it comes to CSS properties, the word-break attribute is able to split words across lines at specific points (such as the first character extending beyond a certain length). Surprisingly, there seems to be no existing CSS method (even with limited supp ...