Adjusting the opacity and grayscale filter of the background image to create a black and white, transparent effect

I was looking to create a semi-transparent and grayscale / black and white background image, so I put together the following code by combining snippets from different discussions on Stackoverflow.

body {
    position: relative;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}
body::after {
  content: "";
  background: url('<?php echo $background[0]; ?>');
  opacity: 0.5;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;  
    filter: grayscale(100%); /* Current draft standard */
    -webkit-filter: grayscale(100%); /* New WebKit */
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%); 
    -o-filter: grayscale(100%); /* Not yet supported in Gecko, Opera or IE */ 
    filter: url(resources.svg#desaturate); /* Gecko */
    filter: gray; /* IE */
    -webkit-filter: grayscale(1); /* Old WebKit */  
}

This is how it's functioning:

Chrome: working

Firefox: background image not visible

Safari: opacity works, but filter does not

Recent versions of IE: opacity works, filter does not

Any insights on this issue would be greatly appreciated.

Thank you.

Answer №1

Make sure the unprefixed is positioned at the bottom! Furthermore, if your page lacks content, consider setting a minimum height for the body:

    html{
      height: 100%;
    }
    body {
        position: relative;
        background-size: 100% 100%;
        background-repeat: no-repeat;
      min-height: 100%;
    }
    body::after {
      content: "";
      background: url('http://jsequeiros.com/sites/default/files/imagen-cachorro-comprimir.jpg') no-repeat center center;
      background-size:cover;
      opacity: 0.5;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      position: absolute;
      z-index: -1;  
      -webkit-filter: grayscale(1); /* Old WebKit */
      filter: grayscale(1);
    }
A Majestic Tiger!

Additionally, there is no need for prefixes like moz, ms or o as they either support the unprefixed version or not at all.

Visit the Codepen link to view the code in action: http://codepen.io/vandervals/pen/VLmbpx

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

Positioning information below every row within a table

I need to display custom data below each row in a table. This is what I have tried: <table class="table" id="foo"> <tr> <th> Name </th> <th> Detail </th> ...

When you hover, a panel will slide in from the right. When you move the mouse

Hey everyone, I've been trying to implement the solution provided but I seem to be missing something. Can you take a look at my fiddle? http://jsfiddle.net/cancerian73/Ej5k8/ body { position: relative; min-height: 3000px; margin: 0; padding: 0; to ...

Tips for Achieving a Smooth Transition Effect with jQuery while Modifying an Image's Attribute

I am facing an issue with the code I have written to change the image source on mouse hover. While it does change the image src, the effect is quite jerky and abrupt. Is there a way to slow down the animation effect? <script> $(document).re ...

Experiencing problems with the CSS styles after including the file.php in

I have a main PHP page called index.php where all other PHP files are included using index.php?page=example. These pages are located in a separate folder, as shown below: public_html/index.php public_html/css/style.php public_html/pages/ The index.php fi ...

CSS, Assistance in incorporating a sub menu into a drop-down menu

I'm looking to enhance my drop down menu by adding a sub menu. Specifically, I would like to create a sub menu for Item 3 in the HTML below. How can I achieve this? Thank you, Below is my CSS code: .nav_menu { width:100%; background-color:# ...

Transforming the hue of a Bootstrap button

I'm feeling a bit frustrated because I expected my code to work and shouldn't have to ask this question. Currently, I am working with bootstrap and trying to customize the default blue color of the btn btn-primary class to something different. ...

Switch between display modes using a button and CSS media query

I'm trying to find the most effective method for toggling display states on a webpage using a button while also being able to adjust based on screen size. For larger screens, I want to default to a horizontal layout with the option to switch to vertic ...

The submenu descends a bit further than its intended position

Hey everyone, hope you had a fantastic New Year! I've run into an issue with the CSS navigation menu submenu items on my WordPress site. https://i.sstatic.net/dY90P.png In the screenshot provided, you can see that the sub-submenu is not displaying ...

Centered image in circles positioned horizontally and vertically, all styled in Bootstrap 4

I am currently working on achieving a design similar to the one shown in the image below using Bootstrap 4 and CSS: https://i.sstatic.net/now05.png Here is the CSS code I have developed so far: .inner-circle { display: block; height: 70px; w ...

Implement a collapsible navbar using bootstrap

To create a responsive navbar that collapses into a burger menu when clicked, you can use the following HTML structure: <body> <header id="nav-wrapper"> <img id="logo" src="images/event-logo.png" /> <nav class="n ...

Effortless floating made possible by the magic of Twitter Bootstrap

I am currently working with a group of elements that are designated as row-fluid and span12, each containing span4 elements. My goal is to have these elements automatically align in columns of 3, regardless of how many are present. However, I am facing an ...

React does not recognize the use of `.css` or `.scss` files for styling

Recently, I encountered an issue with my React code where inline styles were working fine: render() { return ( <div style={{ fontSize: 48 }}>LOLOLO</div> ) } However, when I tried using index.css (which defines .me { font-size ...

Is there a way to position one DIV behind another?

Hey, I'm working on my first project and running into some trouble with divs. I'm trying to position the firework behind the central text but can't figure it out. Can anyone lend a hand? I need to add more details in order to submit the que ...

What is the method for making an unordered list float to the right side of the page

I'm running into an issue with a specific element on the tools bar of my website's product page. I am trying to position it so that it floats to the right of the breadcrumb navigation, aligning perfectly inline with it. However, it stubbornly kee ...

Why does my anchor disappear after a second when clicked to show the image?

Hi everyone, I'm having an issue with a dropdown menu that I created using ul and anchor tags. When I click on one of the options, an image is supposed to appear. However, the problem is that the image shows up for just a second and then disappears. I ...

Launch the jQuery Fancybox on a separate webpage

I am facing an issue where I have a link in my index.html page and I need it to open a div located in another page named index2.html, but for some reason, it is not working. This is the code I currently have: Link in index.html <a href="#modal" id="o ...

Creating an inclusive h1 header with a logo: A step-by-step guide

Is there a way to have a logo linked to the homepage and also have an h1 element that is invisible? This is my current layout: <header id="pageHeader"> <h1> <a href="<?php bloginfo('url'); ?>"> & ...

What are some ways to implement Bootstrap Carousel without having to include CSS?

Utilizing the Bootstrap Carousel, I include it via: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin=" ...

Using the jQuery Selector with multiple IDs will yield different results compared to using a single ID selector

Initially, I set up some dropdown menus to determine which one has been selected and then load the elements with no issues. However, when I added a new set of dropdowns, my existing function started applying to this one as well because it was too broad. ...

Place the collapsible button on the right side of the navigation bar

Looking to position the collapsible button to the right of the navbar in Bootstrap v4, I attempted wrapping the button in: <div class='nav navbar-nav navbar-right'> I also tried adding the float-xs-right class without any luck. A sample ...