background needs to have gradient - css

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.

Related

CSS Gradient in IE8 Disables my Dropdown menu

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.

How to mimic Photoshop "Color Overlay" in CSS

I have a button designed with Photoshop. The button has a gradient defined and I know how to generate it using Ultimate CSS Gradients Tool.
The problem is the button also has a 'Color Overlay' and I don't know how to convert it to css terms?!
UPDATE:
O.K, just to clarify, I know CSS quite well and i know how to set styles to elements.
I have this gradient:
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2IzYjdiZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9Ijg1JSIgc3RvcC1jb2xvcj0iIzZhNzI3ZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, rgba(179,183,189,1) 0%, rgba(106,114,125,1) 85%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(179,183,189,1)), color-stop(85%,rgba(106,114,125,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* IE10+ */
background: linear-gradient(to bottom, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* W3C */
But like i mentioned, In photoshop there is also a Color Overlat defined which makes the button a bit darker, so in photoshop the button looks darker then in the browser, So my question is how do i combine the gradient and the Color Overlay in one CSS rule to make the button look exactly the same as in photoshop.
Update:
Demo
A little better button Demo
Demo with overlay
Just declare a class for button say .design
.design {
/* Gradient code goes here */
}
Now you can use this class as follows
<button class="design">Designed Button</button>
OR
<input type="button" class="design" value="Designed Button" />
For the COLOR OVERLAY, you can wrap the button inside a div with
display: inline-block and position: relative so that it will wrap
the button appropriately and use another div which is positioned
absolute inside the wrapper div with a height and width defined as
100% and assign opaque background color using rgba() and define
opacity as needed
Also if you want to be precise with your CSS declarations, you can particularly define .design class as input[type=button].design or button.design whatever you use, so that .design will not be applied to any other element

Adding gradient to element breaks CSS functionality in IE

I am working on a CSS-based drop-down menu. It works fine until I add gradient to elements. Than something breaks in IE and when I hover over <li> items in sub-menu the menu box disappears.
Here's the code I use to add gradient and make it cross-browser compatible:
background-color: #c1ddf4; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c1ddf4', endColorstr='#ffffff', GradientType=0); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #c1ddf4), color-stop(100%, #ffffff));/* for webkit browsers */
background: -moz-linear-gradient(top, #c1ddf4, #ffffff); /* for firefox 3.6+ */
background-image: -o-linear-gradient(#c1ddf4, #ffffff);
Please see the following examples:
OK (without gradient) vs. NOT OK (with gradient)
The IE filter will break certain functionality when applied to elements. My suggestion is to use a horizontally tiled gradient image for IE, either by using a CSS hack, an IE-only style sheet, or targeting it using Modernizr.js.
The truly proper way would be to use Modernizr, then write this CSS:
.no-cssgradients li {
background: url(gradient.png) repeat-y;
}
That way, any browser that doesn't support CSS gradients (not just IE) will get served the image instead.

CSS (perhaps with Compass): Cross-browser gradient

I would like to get a gradient in CSS (perhaps through Compass) that works in every major browser, including IE7+. Is there an easy way to do this (without writing a lot of code, and without a custom image file)?
I looked at Compass's gradient mixin, but it does not work with Internet Explorer.
Any ideas? (It does not need to be Compass -- I am happy install something else.)
Edit: What I am trying to get is some framework (like Compass?) that generates code like what Blowsie posted that's been tested across browsers. Basically like the Compass gradient mixin I mentioned, but with IE support. (I am a bit wary of just rolling my own SCSS mixin and pasting in blocks like Blowsie's code, because I haven't tested it and do not have the resources to do so.)
I just noticed that the current Compass beta (0.11.beta.6) has support for generating IE gradients in the compass/css3/images module (which supersedes the previous gradient module), so you can generate your gradients with a total of two short commands:
#import "compass/css3/images";
#import "compass/utilities/general/hacks"; /* filter-gradient needs this */
.whatever {
/* IE; docs say this should go first (or better, placed in separate IE-only stylesheet): */
#include filter-gradient(#aaaaaa, #eeeeee);
/* Fallback: */
background: #cccccc;
/* CSS 3 plus vendor prefixes: */
#include background(linear-gradient(top, #aaaaaa, #eeeeee));
}
This generates the following slew of CSS:
.whatever {
*zoom: 1;
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FFAAAAAA', endColorstr='#FFEEEEEE')";
filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FFAAAAAA', endColorstr='#FFEEEEEE');
background: #cccccc;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #aaaaaa), color-stop(100%, #eeeeee));
background: -moz-linear-gradient(top, #aaaaaa, #eeeeee);
background: -o-linear-gradient(top, #aaaaaa, #eeeeee);
background: linear-gradient(top, #aaaaaa, #eeeeee);
}
I guess I would have preferred to have the IE and non-IE gradient code in one call, but since IE's DXImageTransform gradient function is pretty limited, that is probably not possible.
The code I use for all browser gradients..
background: #0A284B;
background: -webkit-gradient(linear, left top, left bottom, from(#0A284B), to(#135887));
background: -moz-linear-gradient(top, #0A284B, #135887);
background: -o-linear-gradient(#0A284B, #135887);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0A284B', endColorstr='#135887');
zoom:1;
You will need to specify a height or zoom:1 to apply hasLayout to the element for this to work in ie
While gradients are of limited complexity, they're complex enough to require what you would consider "lots of code".
Consider:
starting colour, ending colour and the hexadecimal math required to transition between one and the other
The number of "steps"
The width/height of each step
Since there is no pure CSS way of doing this, it means rendering HTML, one element for each colour/step, without messing up your existing HTML
So, no, without a plug-in that does all of this for you, it would require a bit of code, or an image.

IE adds blue border to div where css gradient is used

I'm trying to make a gray line, that is fading out to transparent. I created a div, that is 1x100px, and added css gradient to make the fade effect.
It works fine, except in IE where the div gets a blue border, which I cant get rid off.
This is my css for the div
#left_header_border {
position:absolute;
bottom:-1px;
left:-100px;
width:100px;
height:1px;
/* gradient */
background-color: transparent;
background-image: -moz-linear-gradient(left, transparent, #cccccc); /* FF3.6 */
background-image: -o-linear-gradient(left, transparent, #cccccc); /* Opera 11.10+ */
background-image: -webkit-gradient(linear,left bottom,right bottom,color-stop(0, transparent),color-stop(1, #cccccc)); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient(left,transparent, #cccccc); /* Chrome 10+, Saf5.1+ */
background-image: linear-gradient(left, transparent, #cccccc);
filter: progid:DXImageTransform.Microsoft.gradient(gradientType=1, startColorStr='transparent', EndColorStr='#cccccc'); /* IE6–IE9 */
}
I've tried to inspect the div, and make it higher, and the gradient seems to work, but the color is blue, and a border is added. Why?
Change the filter to:
filter: progid:DXImageTransform.Microsoft.gradient(gradientType=1, startColorStr='#00cccccc', EndColorStr='#ffcccccc'); /* IE6–IE9 */
The filter doesn't allow “transparent” as a color value, but it does allow you to use an 8-digit hex reference, where the first two digits specify the opacity of the colour (just like the last value in rgba() color references).
More on using RGBA and transparency & using MS Filters
if the scary maths bit gets you, you can find e.g. 0.6 transparency in Windows calculator, open it in scientific view, do 255*0.6 = 153 then click the "hex" checkbox for the conversion = 99
in the example above it was starting at the the fully transparent (0.0 opacity) = 255*0 = hex value "00" through to fully opaque (1.0 opacity) = 255*1 = hex value "ff"
Update As kindly linked by thirtydot in the comments, here's a handy converter from RGBa to MS Filter syntax
I'd recommend using CSS3Pie instead of hard-coding the filter style for this sort of thing -- it's a lot easier and more standards-compliant; it allows you to use standard CSS3 for your gradients in older versions of IE.

Resources