Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to make the whole page in grayscale except specified div

I have a css code that could make the whole page in grayscale.

<style type="text/css">
html {
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    filter: grayscale(100%);
}
</style>

I now want to embed an iframe inside a div that would not be affected. I have searched about the solution and fount :not selector. When I refer to 6.6.7 at http://www.w3.org/TR/css3-selectors/#negation I think i have found the solution because it may work even I put html as my css selector

html|:not(x)

So I changed the code just like the above code but nothing changed. I was worried about the problem is caused by the design of my website so I decided to code them in jsfiddle in the most simple HTML

<div id="abc" class="abc"><font color="red">This should be a normal text.</font></div>
<font color="red">This should be an affected text.</font>

In CSS

html|*:not(.abc) {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
filter: grayscale(100%); }

Link: http://jsfiddle.net/4vxyqdye/1/ PS: In the previous version I used :not(.abc) only but all elements become grayscale.

like image 741
AkiEru Avatar asked Sep 28 '14 16:09

AkiEru


People also ask

How do I convert an image to grayscale in CSS?

The grayscale() CSS function converts the input image to grayscale. Its result is a <filter-function> .

How do you grayscale in HTML?

Converts the image to grayscale. 0% (0) is default and represents the original image. 100% will make the image completely gray (used for black and white images). Note: Negative values are not allowed.

How do I use grayscale in CSS?

The grayscale() function in CSS is an inbuilt function that is used to apply a filter to the image to set the grayscale of the image. Parameters: This function accepts a single parameter amount that holds the value of grayscale. The value of grayscale is set in terms of number and percentage.

What is filter grayscale?

grayscale()Converts an element's color to a shade of gray, for use by the filter property. A decimal value between 0 and 1 or percentage up to 100% controls the extent of the gray effect. This CSS property value is reflected in the following image: filter: grayscale(1); filter: grayscale(100%); /* same */


1 Answers

Think in the weight of selectors, html is a general selector, less heavy than more specific selectors, like clases or IDs, if you do something like :

html {
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    filter: grayscale(100%);
}

html .class-you-wanna-exlude {
   -webkit-filter: grayscale(0%);
   -moz-filter: grayscale(0%);
   filter: grayscale(0%);
}

i think this will solve your issue.

like image 71
Damian Cardozo Avatar answered Oct 03 '22 05:10

Damian Cardozo