I've created radial-gradient
background: radial-gradient(ellipse at center, #595959 0%, #000000 40%);
And as far as I know, this should help me to make it cross-browser
background: -webkit-radial-gradient(ellipse at center, #595959 0%, #000000 40%);
background: -moz-radial-gradient(ellipse at center, #595959 0%, #000000 40%);
background: -ms-radial-gradient(ellipse at center, #595959 0%, #000000 40%);
background: -o-radial-gradient(ellipse at center, #595959 0%, #000000 40%);
background: radial-gradient(ellipse at center, #595959 0%, #000000 40%);
However this isn't support IE-9 and after some searching, I found this:
Create a radial gradient for Internet Explorer 6/7/8 but this doesn't seem to work anymore. And well, I'm curious how to make my gradient work in IE-9. Thanks
I think I have bad news for you.
IE9 dropped support for the old IE-specific filter styles -- ie the ones that you pointed out in the other question you linked to.
The intention was that IE9 was supposed to be properly standards compliant, and those filter styles were non standard so they were dropped. At the same time, the idea was all the functionality provided by those styles was being replaced by standards-based CSS features.
Unfortunately, as you're finding, not quite all of the functionality was replaced with standard CSS in IE9. In particular, CSS gradients were a noticeable omission and have caused a lot of code to be written using awkward work-arounds.
The bottom line is that IE9 specifically has a particular blind-spot in this area, where newer IE versions and even the older ones do support this feature one way or another.
Your only real ray of light is that IE9 usage has dropped through the floor recently; hardly anyone is still using it. So my advice is that you can probably get away with having a fall-back solution that just uses a plain background colour; let IE9 have that and concentrate on the newer browsers that people do actually use.
I'm giving my a linear gradient but in Firefox, even new versions, what I get is something like bars of solid color building the gradient. This is what's in my CSS:
background-color: #d3d3d3;
background-repeat: repeat-x;
background: -moz-linear-gradient(top, rgba(145,145,142,1) 0%, rgba(253,253,253,1) 99%);
background: -webkit-gradient(linear, left top, left bottom, from(#d3d3d3), to(#fcfcfc));
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#d3d3d3',endColorstr='#fcfcfc');
background: -o-linear-gradient(rgb(211,211,211),rgb(253,253,253));
According to this, it is most unlikely you are facing a version problem. Firefox, as usual, was the first to implement a standards-compliant (no prefix) CSS property (and it has already been 9 versions back).
Try removing the background-repeat property as it is mostly useless for gradients unless you've set a background size. If it solves, I'd recommend posting a bug report on Bugzilla. Does it work well on IE10 and Chrome?
Website in question: http://atlanticsig.creativecurvedev2.ca/
A little background... This is a development site for a client that I am building in MODx using the Wayfinder extension for the menu and Ultimate Dropdown for the sub-menu. I am using CSS gradients to produce the pretty background color for the menu.
My issue is that in IE8, the drop-down menu does not display for the header navigation when I incorporate a "filter" gradient background color. Only the IE8 browser has this issue; even IE7 works properly. The drop-down menu is there, technically, because the cursor can click on the sub-menu links, but the browser refuses to show them.
I have fixed the issue by using a repeated background image for IE8, but I really didn't want to go this route; I thought for sure there should be a CSS solution, which is why I am posting this; my curiosity is piqued and I would like to see what the real issue was.
I was able to track down the issue to this line of code:
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-8 */
As soon as I removed this line from the following block of code, the drop-down menu would work fine in IE8, however the gradient would disappear:
#header_menu {
background: -moz-linear-gradient(top, #003764 0%, #3b6b89 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#003764), color-stop(100%,#3b6b89)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #003764 0%,#3b6b89 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #003764 0%,#3b6b89 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #003764 0%,#3b6b89 100%); /* IE10+ */
background: linear-gradient(to bottom, #003764 0%,#3b6b89 100%); /* W3C */
background-color: #003764; /* Old browsers */
height: 38px;
width: auto;
}
I tried a number of fixes in the HTML and CSS, including various arrangements of the gradients, applying the gradients to different elements, applying various heights/widths/position values to my containers and menus, playing with z-index values, adding extra blocks, etc.
In the end, it always seemed to come back to that "filter" line (I even tried -ms-filter-).
If you would like snippets of any other pieces of code, just let me know. This is a pretty interesting issue that I has made me genuinely curious to solve.
In all honesty, using IE's filter style is always asking for trouble -- it has a whole load of bugs and quirks that can break other stuff unexpectedly.
So what are your options?
You could try using CSS3Pie to render your gradients. It uses VML rather than filters, so it won't suffer from the same bugs. (or you could write the VML code yourself, but that would be tedious)
Or you could use a graphic for the gradient in IE8. You could arrange the CSS code such that the standard CSS gradient overrides the background graphic, so other browsers could carry on using the CSS gradient and wouldn't need to know about the graphic.
Or you could just accept that IE8 is an old browser and give it a plain background rather than a gradient. It may not look as pretty but it'll still work, and people still using IE8 are probably used to seeing sites these days that don't look their best.
Is anyone aware of a way to change one layer of a multi-layered background using CSS?
I've been searching around but can't find any mention of current, or even proposed future specification. My thinking says there probably wont be, but the net is so vast now I'm sure someone, somewhere, has information or links to discussions along these lines.
The following example would obviously have problems with regard to the order of precedence when applied to different elements:
.building-texture {
background: transparent, url(image/building-side.png);
}
.shade-dark {
background: url(image/shade-dark.png), unchanged;
}
.shade-mid {
background: url(image/shade-mid.png), unchanged;
}
.shade-light {
background: url(image/shade-light.png), unchanged;
}
<div class="building-texture shade-dark"></div>
Obviously there are a number of workarounds for the above, but none are ideal, especially when you start talking about a lot of different 'layer states' and a number of different 'textures':
Initial solutions
combined classes
This is the most optimal of the fallbacks, but gets ridiculous when you start to take vendor prefixes into account and when dealing with more than two layers.
.building-texture-shade-dark {
background: url(image/shade-dark.png), url(image/building-side.png);
}
.building-texture-shade-mid {
background: url(image/shade-mid.png), url(image/building-side.png);
}
.building-texture-shade-light {
background: url(image/shade-light.png), url(image/building-side.png);
}
separate elements
When running through some tests locally, I found that multi-layered backgrounds performed faster than using sub-elements. In fact for most modern browsers, even introducing a simple child (with no background applied) slowed the rendering down quite a bit.
<div class="building-texture">
<div class="shade-dark"></div>
</div>
JavaScript generation
To get over the pain of hand-typing the first option (combined classes), JavaScript could be used to generate the stylesheet. But you still have the awkwardness of the long class names. Plus when you want to change one applied effect of the combined class (e.g. remove shading), you have to script an ability to work out how to do so based on naming convention.
Style property via JavaScript
The other option is to dynamically rewrite the entire background via .style on each element. I haven't tested this, but my head tells me that this will be rather inefficient, as I'm sure the browsers are able to do quite a few optimisations when dealing with preset classes (i.e. by grouping element rendering by classification). Although I could be wrong.
Why...
I'm playing around with CSS 3D transforms (with perspective enabled) and how best to texture/light such structures in a simple and fast manner (example code):
http://pebbl.co.uk/wote/
(source: pebbl.co.uk)
After failing at producing a CSS solution I was happy with, I'm currently heading toward a Canvas-based solution that would pre-build all the textures I may want—along with their different shaded states—which would then generate a cached data URI to be attached as a single layer background. My tests have shown this to be optimal. However, I'd really like to use as many native browser-based solutions as possible, because with canvas there is a lot more code involved, and, because today's browsers are improving so quickly, it seems foolish to reinvent any wheels, engines, or road networks.
Even if it might be deemed that what I'm doing is not a 'proper' use of CSS, in my opinion, each background item is it's own unit—and to me it makes sense that there should be some specified way to modify each unit separately... even if it's way off in the future.
I'd be interested in any answers with links to discussions along these lines.
Unfortunately there is no way to do that in regular CSS. You can only change an entire property, not part of it. Which is why we have separate properties like background-image, background-color to start with. But nothing more fine-grained than that.
As ScottS suggested, pseudo-elements could be a way to go but you will probably have the same problems as multiple separate div elements.
If your main goal is to avoid typing code over and over, a good solution would be to use a CSS preprocessor like SASS. Your SCSS would then be something like this:
$img-side: url("image/building-side.png");
$img-dark: url("image/shade-dark.png");
$img-mid: url("image/shade-mid.png");
$img-light: url("image/shade-light.png");
.building-texture {
background: transparent, $img-side;
}
.shade-dark {
background: $img-dark, $img-side;
}
.shade-mid {
background: $img-mid, $img-side;
}
.shade-light {
background: $img-light, $img-side;
}
It would compile down to the more bulky CSS (with full URL definitions) but you certainly save a lot on development time. SASS can also help you generate the vendor prefixes using mixins (there is also Compass which adds that to SASS).
In fact, there is an upcoming CSS variables spec which you may be able to use in future, however I don't think any browsers support it yet.
Abstract it with Pseudo Elements
I am not aware of any way to "swap" a single background yet. One workaround is based off the "separate elements" technique, but the inner element is a pseudo-element instead. I have no idea about rendering speed. It also has the drawback that it will not work for IE8, as you cannot apply filter to pseudo-elements. However, since you are using the idea in conjunction with CSS3 perspective and such, the IE8 caveat is not an issue for you.
This achieves the abstraction of the texture from the shading. It could even add another layer through an :after pseudo-element, and it still could use multiple backgrounds in each of the three if needed/desired.
Here is the fiddle.
Sample Code:
HTML
<div class="texture"></div>
<div class="texture light"></div>
<div class="texture medium"></div>
<div class="texture dark"></div>
CSS (core)
.texture {
position: relative;
background: url(http://www.dummyimage.com/12x16/ff0000/ffffff.png&text=X++) top left repeat;
}
.light:before,
.medium:before,
.dark:before {
content: '';
position: absolute;
top:0;
right: 0;
bottom:0;
left: 0;
}
.light:before {
background: -moz-linear-gradient(left, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.1) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(0,0,0,0.3)), color-stop(100%,rgba(0,0,0,0.1)));
background: -webkit-linear-gradient(left, rgba(0,0,0,0.3) 0%,rgba(0,0,0,0.1) 100%);
background: -o-linear-gradient(left, rgba(0,0,0,0.3) 0%,rgba(0,0,0,0.1) 100%);
background: -ms-linear-gradient(left, rgba(0,0,0,0.3) 0%,rgba(0,0,0,0.1) 100%);
background: linear-gradient(to right, rgba(0,0,0,0.3) 0%,rgba(0,0,0,0.1) 100%);
}
.medium:before {
background: -moz-linear-gradient(left, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.2) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(0,0,0,0.6)), color-stop(100%,rgba(0,0,0,0.2)));
background: -webkit-linear-gradient(left, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.2) 100%);
background: -o-linear-gradient(left, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.2) 100%);
background: -ms-linear-gradient(left, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.2) 100%);
background: linear-gradient(to right, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.2) 100%);
}
.dark:before {
background: -moz-linear-gradient(left, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.3) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(0,0,0,0.8)), color-stop(100%,rgba(0,0,0,0.3)));
background: -webkit-linear-gradient(left, rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.3) 100%);
background: -o-linear-gradient(left, rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.3) 100%);
background: -ms-linear-gradient(left, rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.3) 100%);
background: linear-gradient(to right, rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.3) 100%);
}
I am totally a noob to css and I have a need to add gradient to the background image on the top of the page.
here is what I tried but obviously its not working as background overwriting the value. How can I fix it
I have a background image and I need a gradient on top of it. Here is my css
body.test {
/* Mozilla: */
background: -moz-linear-gradient(top, #00FF00, #000000);
/* Chrome, Safari:*/
background: -webkit-gradient(linear,
left top, left bottom, from(#00FF00), to(#000000));
/* MSIE */
filter: progid:DXImageTransform.Microsoft.Gradient(
StartColorStr='#00FF00', EndColorStr='#000000', GradientType=0);
background: url(../mybackground.png);
}
TEST HERE
http://jsfiddle.net/PsDuF/
First, have a look at this tool for creating CSS gradients.
change
background: url(../mybackground.png);
to
background-image: url(../mybackground.png);
background is the shorthand syntax. Alternatively, you could combine the image with your other syntax:
background: url(../mybackground.png), -moz-linear-gradient(top, #00FF00, #000000);
In your case, you are declaring background multiple times, so each time you declare it, you are over-riding the previous declaration.
When you declare multiple background in one declaration, the order you declare them will change the stacking order. JSBIN example using images and mozilla background gradients: jsbin.com/abumuz/1
Note that if you want the gradient on top of the image, but still want to see the image, you need to make sure your gradient has alpha transparency.