I am looking for a perfect solution for cross browser linear gradient including IE 8 and below support.
this is my current code
background: rgba(0,0,0,0.6);
background: -webkit-gradient(linear, center top, center bottom, from(transparent), to(rgba(0, 0, 0, .6)));
background: -webkit-linear-gradient(transparent, rgba(0, 0, 0, .6));
background: linear-gradient(transparent, rgba(0, 0, 0, 0.6)) repeat scroll 0 0 rgba(0, 0, 0, 0);
I want to generate the same effect for different browsers.
Please let me know how to get the exact same effect on all browsers by adding cross browser css code.
Thank you.
My issue is caused by having a background gradient on top of an image.
How do I add the other properties e.g. -webkit, -o, to make it work in other browsers
div{
background:
linear-gradient(
rgba(0, 0, 0, 0.2),
rgba(0, 0, 0, 0.8)
),
url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg');
}
http://jsbin.com/rovini/1/edit?html,css,output
EDIT
If I add the vendor prefixes like so:
div{
background:
-mox-linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.8)),
-webkit-linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.8)),
-o-linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.8)),
linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.8)),
url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg');
}
It does not work
You can use this. JSFIDDLE
div{
height:100%;
width:100%;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,.2)), to(rgba(0,0,0,.8))),url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg'); /* Saf4+, Chrome */
background: -webkit-linear-gradient(top, rgba(0,0,0,.2), rgba(0,0,0,.8)),url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg'); /* Chrome 10+, Saf5.1+ */
background: -moz-linear-gradient(top, rgba(0,0,0,.2), rgba(0,0,0,.8)),url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg'); /* FF3.6+ */
background: -ms-linear-gradient(top, rgba(0,0,0,.2), rgba(0,0,0,.8)),url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg'); /* IE10 */
background: -o-linear-gradient(top, rgba(0,0,0,.2), rgba(0,0,0,.8)),url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg'); /* Opera 11.10+ */
background: linear-gradient(to bottom, rgba(0,0,0,.2), rgba(0,0,0,.8)),url('http://www.nhm.ac.uk/resources-rx/images/1007/women-artists-peach-banner_128346_2.jpg'); /* W3C */
}
div {
background: -webkit-linear-gradient(left,rgba(0,0,0,0.2),rgba(0,0,0,0.8)); /*Safari 5.1-6*/
background: -o-linear-gradient(right,rgba(0,0,0,0.2),rgba(0,0,0,0.8)); /*Opera 11.1-12*/
background: -moz-linear-gradient(right,rgba(0,0,0,0.2),rgba(0,0,0,0.8)); /*Fx 3.6-15*/
background: linear-gradient(to right,rgba(0,0,0,0.2),rgba(0,0,0,0.8)); /*Standard*/
}
You can see full examples from w3schools. Just remember to put the standard syntax last.
Original answer
What you need are called vendor prefixes. These allow support for css3 features which are not yet applied in general accross the browsers.
the simple syntax is: -prefix followed by -property-name
in your case it will be:
-webkit-linear-gradient(...)
-moz-linear-gradient(...)
-ms-linear-gradient(...)
-o-linear-gradient(...)
linear-gradient(...)
webkit is for safari and chrome, moz for firefox, ms for IE and o for opera. But recently, webkit. The final one, without any prefix is for the possibility that the feature gets cross-platform support in future.
Added after 1st comment
you need to put them with along with other css rules for the dom element, ie, if you are writing css for a div with id papaya:
div#papaya{
color: ...;
font-size: ...;
-webkit-linear-gradient(...);
-moz-linear-gradient(...);
-ms-linear-gradient(...);
-o-linear-gradient(...);
linear-gradient(...);
/*any other properties*/
}
This is just a shorthand way of grouping multiple background properties:
background: url('cats.jpg'), #000000;
which equates to
background-image: url('cats.jpg');
background-color: #000000;
What I wrote originally did not work because the browser looked at the 'background' property and couldn't understand the values I had used (the vendor prefixes).
Unfortunately, because I was stacking a gradient over an image, the vendor prefixes could not all be included in one reference to background. So, like Vlada903 said, the vendor prefixes need to be in their own reference to background so the browser can scan each, before finding the one it is able to understand and use.
Using CSS3, what RGB-like value should replace VALUE below in order to achieve a solid black background that is 95% transparent?
div { background: VALUE }
Thanks Folks!!!
RGBa (a for alpha)
div { background: rgba(0, 0, 0, .05)};
You can use an RGBA notation.
R for red, G for Green, B for Blue and the A for aplha (percentage of transparency, as you've asked).
So the best answer is :
div {
background : rgba(0, 0, 0, .95);
}
And don't worry, it's supported by all the major browsers (even IE since IE 9) : http://caniuse.com/css3-colors
RGBa, i think:
div {
background:rgba(0, 0, 0, 0.95);
}
Folks i took a challenge test online and the following is the answers they provided to my question above:
div { background:rgba(0, 0, 0, 0.05); }
To check, I ran a test on my system and #Blingue is definitely correct.
Use div {background:rgba(0,0,0,0.05)}
it's useful when developing to know all the css properties implemented for specific element but chrome stable release doesn't do that,
here is and example, the body element have gradient background but of course to implement this on all the browsers you have to do this
background: -webkit-gradient(radial, center center, 500, center center, 1400, from(transparent), to(rgba(0, 0, 0, 0.6))) white;
background: -webkit-radial-gradient(farthest-side, transparent 90%, rgba(0, 0, 0, 0.2) 150%) white;
background: -moz-radial-gradient(farthest-side, transparent 90%, rgba(0, 0, 0, 0.2) 150%) white;
background: -ms-radial-gradient(farthest-side, transparent 90%, rgba(0, 0, 0, 0.2) 150%) white;
background: -o-radial-gradient(farthest-side, transparent 90%, rgba(0, 0, 0, 0.2) 150%) white;
background: radial-gradient(farthest-side, transparent 90%, rgba(0, 0, 0, 0.2) 150%) white;
like here
so when you inspect the body element in chrome stable release you get this
but in the canary you get this
so is there away to enable the stable release to show all the repetitive properties?
Well, Chrome simply ignore the properties that are not targeted to him ... it's normal. If you want to test / debug your code for other properties (with other vendor prefix) you should test / debug them with the right browser : chrome dev tools are not made for this.