Using CSS for Gradients in Backgrounds
Gradients may be used in backgrounds via CSS. This is not available by CSS in all browsers, but, the feature is coming along. Even browsers that support gradients may have some holes in their functionality. This feature is defined in CSS3, use it and include fallback handling. Though the CSS3 version is not supported by all new browsers, it will be available soon. It has been available for webkit, opera, mos, and ms for some time, at least to some level. The following explains how the gradient can be used reasonably reliable across browsers. While the oldest Safari and Chrome syntax is shown in the cross browser samples, they are very different format from the current CSS3 syntax. That will be used, but, not discussed here. Meanwhile the new Mozilla, and the more recent webkit, mos and ms are very similar in format to the CSS3 syntax, and will be discussed below.
Plan for the following format in the future:
linear-gradient (angleOrlocation, stop1 [%], stop2 [%], [stop3 [%], […]]])
-
angleOrlocation – This indicates the location/direction that the gradient will go. The value may be:
- Defined in degrees, such as 30degree, or 190deg
- Listed as {top, bottom, left, right, top left, top right, bottom left, bottom right, circle}, indicating where the gradient starts. Top would result in vertical gradient from top to bottom. Left would result in horizontal running left to right
- stop1 x% – the color to start gradient and an optional percent, identifying where the stop is located, effecting the width of the transition band.
- stop2 x% – the color to blend to from stop1 and an optional percent, identifying where the stop is located, effecting the width of the transition band
- stop3 x% – the color to blend to from stop2 and an optional percent, identifying where the stop is located, effecting the width of the transition band
- stop x% …. as many color and optional percent, identifying where the stop is located, effecting the width of the transition band
- stopN – the color to blend to from the previous stop.
Note: In the previous discussion, I refer to the positioning of the color by %. Actually, the value can be given in % or other measuring method, such as; px, rem, em, …
radial-gradient([% %,] [type,] [size,] stop1 [%], stop2 [%], [stop3 [%], […]]])
-
[% %] – this is the location of the center of the shape, such as 80% 20%. If this field is not present, the shape is centered in the DIV.
- type – identify if the shape will be {circle, ellipse }. If this field is not present, ellipse is used
- size – the size is specified relative to { closest-side, farthest-side, closest-corner, farthest-corner, contain, cover }
- stop1 x% – the color to start gradient and an optional percent, identifying where the stop is located, effecting the width of the transition band
- stop2 x% – the color to blend to from stop1 and an optional percent, identifying where the stop is located, effecting the width of the transition band
- stop3 x% – the color to blend to from stop2 and an optional percent, identifying where the stop is located, effecting the width of the transition band
- stop x% …. as many color and optional percent, identifying where the stop is located, effecting the width of the transition band
- stopN – the color to blend to from the previous stop.
Note: In the previous discussion, I refer to the positioning of the color and center by %. Actually, the value can be given in % or other measuring method, such as; px, rem, em, …
Using CSS to create a Horizontal Gradient Background on a DIV
Using CSS to Create a Vertical Gradient on a DIV
Using CSS to Include Multiple Band Gradients on a DIV
Using CSS to Create an Even Stop Gradient on a DIV
If you would like an even stop gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.
Using CSS to Create an arbitrary Stop Gradient on a DIV
If you would like an arbitrary stop gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.
Notice the use of 5% and 95% to affect the location at which the color band is to start, and therefore affects the width of the transition bands.
Using CSS to Create a Diagonal Gradient on a DIV
If you would like a diagonal gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.
Notice: To go from top left to bottom right, the standard requires the specification of the end location, bottom right. Safari (webkit) reverses the logic of the location to specify in the first parameter. Webkit expects the use of the begin point of the diagonal. If you want to go from top left to bottom right, specify top left.
Using CSS to Create an Angled Gradient on a DIV
If you would like a gradient at a specific angle on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.
Using CSS to Create a Radial Gradient on a DIV
Notice: for circular gradients, the first parameter is replace with the value circle. You may use the percent on the color bands to position from the center of the circle.
Using CSS to Create a Positioned Radial Gradient on a DIV
If you would like a positioned radial gradient on selected DIV, there is a CSS3 option to handle this situation.
This is available in CSS3, and special case options for old -webkit, and -mos browsers.