|
CSS3 Gradients(Fg. 1)
CSS3 gradients let you display smooth transitions between two or more specified colors.
Earlier, you had to use images for these effects. However, by using CSS3 gradients you can reduce download time and bandwidth usage. In addition, elements with gradients look better when zoomed, because the gradient is generated by the browser.
CSS3 defines two types of gradients:
- Linear Gradients (goes down/up/left/right/diagonally)
- Radial Gradients (defined by their center)
Internet Explorer 10+, Firefox 16+, Chrome 26+, and Opera 12.1+ support the two gradient functions.
Safari 5.1+ requires the prefix -webkit-.
Chrome 10 to 25 require the prefix -webkit-.
Opera 11.1 to 12.0 require the prefix -o-.
Firefox 3.6 to 15 require the prefix -moz-.
Internet Explorer 9 and earlier versions do not support gradients.
|
Fg. 1 (CSS3 Gradients)
#grad
{
background: -webkit-linear-gradient(red, blue); /* For Safari */
background: -o-linear-gradient(red, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(red, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(red, blue); /* Standard syntax */
}
#grad
{
background: -webkit-linear-gradient(180deg, red, blue); /* For Safari */
background: -o-linear-gradient(180deg, red, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(180deg, red, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(180deg, red, blue); /* Standard syntax */
}
|
|
Fg. 2.1 (CSS3 Linear Gradients)
#grad
{
background: -webkit-linear-gradient(red, blue); /* For Safari */
background: -o-linear-gradient(red, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(red, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(red, blue); /* Standard syntax */
}
Fg. 2.2 (CSS3 Linear Gradients)
#grad
{
background: -webkit-linear-gradient(left, red , blue); /* For Safari */
background: -o-linear-gradient(right, red, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, red, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, red , blue); /* Standard syntax */
|
CSS3 Linear Gradients(Fg.s 2)
To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.
This Box Has A Linear Gradient Background!
Syntax
background: linear-gradient(direction, color-stop1, color-stop2, ...);
You can make a gradient diagonally by specifying both the horizontal and vertical starting positions.
If you want more control over the direction of the gradient, you can define an angle, instead of the predefined directions (to bottom, to top, to right, to left, to bottom right, etc.).
background: linear-gradient(angle, color-stop1, color-stop2);
The angle is specified as an angle between a horizontal line and the gradient line, going counter-clockwise. In other words, 0deg creates a bottom to top gradient, while 90deg generates a left to right gradient.
(Fg. 2.1 & Fg. 2.2)
|
CSS3 Radial Gradients(Fg.s 3)
A radial gradient is defined by its center.
To create a radial gradient you must also define at least two color stops. You can also specify the gradient's center, shape (circle or ellipse) as well as its size. By default, center is center, shape is ellipse, and size is farthest-corner.
This Box Has A Radial Gradient Background!
Syntax
background: radial-gradient(center, shape size, start-color, ..., last-color);
The shape parameter defines the shape. It can take the value circle or ellipse. The default value is ellipse. The size parameter defines the size of the gradient. It can take four values: closest-side, farthest-side, closest-corner and farthest-corner
(Fg. 3.1 & Fg. 3.2)
|
Fg. 3.1 (CSS3 Radial Gradients)
#grad
{
background: -webkit-radial-gradient(red, green, blue); /* Safari */
background: -o-radial-gradient(red, green, blue); /* For Opera 11.1 to 12.0 */
background: -moz-radial-gradient(red, green, blue); /* For Firefox 3.6 to 15 */
background: radial-gradient(red, green, blue); /* Standard syntax */
}
Fg. 3.2 (CSS3 Radial Gradients)
#grad
{
background: -webkit-radial-gradient(red 5%, green 15%, blue 60%); /* Safari */
background: -o-radial-gradient(red 5%, green 15%, blue 60%); /* For Opera 11.1-12.0 */
background: -moz-radial-gradient(red 5%, green 15%, blue 60%); /* For Firefox 3.6-15 */
background: radial-gradient(red 5%, green 15%, blue 60%); /* Standard syntax */
}
|