CSS: Linear gradient for background. Linear-gradient(): linear gradient in the background How to make a gradient background in css

CSS gradient represents transitions from one color to another.

Gradients are created using the linear-gradient() and radial-gradient() functions.

The gradient background can be set in the background, background-image, border-image and list-style-image properties.

How to make a gradient in CSS

Browser support

IE: 10.0
Firefox: 16, 3.6 -moz-
Chrome: 26.0, 10.0 -webkit-
Safari: 6.1, 5.1 -webkit-
Opera: 12.1, 11.1 -o-
iOS Safari: 7.1
Opera Mini:
Android Browser: 4.4, 4.1 -webkit-
Chrome for Android: 44

1. Linear gradient linear-gradient()


Rice. 1. Gradient line, start and end points and gradient angle

Linear Gradient created using two or more colors that have a direction specified, or gradient line.

If the direction is not specified, the default value is used - top down.

By default, gradient colors are distributed evenly in a direction perpendicular to the gradient line.

Background: linear-gradient(angle/side or slant by keyword(pair of keywords), first color, second color, etc.);

Direction the gradient can be specified in two ways:
using tilt angle in degrees deg, the value of which determines the angle of inclination of the line inside the element.

Div ( height: 200px; background: linear-gradient(45deg, #EECFBA, #C5DDE8); )

using keywords to top , to right , to bottom , to left which correspond to a gradient angle of 0deg , 90deg , 180deg and 270deg respectively.

Div ( height: 200px; background: linear-gradient(to right, #F6EFD2, #CEAD78); )

If the direction is specified by a pair of keywords, for example, to top left , then the starting point of the gradient will be located in the opposite direction, in this case the bottom right.

Div ( height: 200px; background: linear-gradient(to top left, powderblue, pink); )

For an uneven distribution of colors, the starting position of each color is indicated through the stop points of the gradient, the so-called color stops. Breakpoints are specified in %, where 0% is the starting point, 100% is the end point, for example:

Div ( height: 200px; background: linear-gradient(to top, #E4AF9D 20%, #E4E4D8 50%, #A19887 80%); )

For a clear distribution of color stripes, each subsequent color must begin from the stopping point of the previous color:

Div ( height: 200px; background: linear-gradient(to right, #FFDDD6 20%, #FFF9ED 20%, #FFF9ED 80%, #DBDBDB 80%); )

2. Radial gradient radial-gradient()

Radial Gradient differs from linear in that the colors come from one point (the center of the gradient) and are evenly distributed outward, drawing the shape of a circle or ellipse.

Background: radial-gradient(gradient shape/size/center position, first color, second color, etc.);

Gradient shape defined by the keywords circle or ellipse . If no shape is specified, the radial gradient defaults to an ellipse shape.

Div ( height: 200px; background: radial-gradient(white, #FFA9A1); )

Center position specified using the keywords used in the background-position property, followed by the at prefix. If the center position is not specified, the default value at center is used.

Div ( height: 200px; background: radial-gradient(at top, #FEFFFF, #A7CECC); )

A pair of values, specified in % , em , or px length units, can control the size of the elliptical gradient. The first value specifies the width of the ellipse, the second – the height.

Div ( height: 200px; background: radial-gradient(40% 50%, #FAECD5, #CAE4D8); )

Gradient size specified using keywords. The default value is farthest-corner.

div ( height: 200px; background: radial-gradient(circle farthest-corner at 100px 50px, #FBF2EB, #352A3B); )

Using a radial gradient, you can create realistic three-dimensional shapes, such as balls and buttons.

Ball

div ( width: 200px; height: 200px; border-radius: 50%; margin: 0 auto; background: radial-gradient(circle at 65% 15%, aqua, darkblue); )

Button

.wrap ( height: 200px; padding: 50px 0; background: #cccccc; ) .button ( width: 100px; height: 100px; border-radius: 50%; margin: 0 auto; background: radial-gradient(farthest-side ellipse at top left, white, #aaaaaa); box-shadow: 5px 10px 20px rgba(0,0,0,0.3), -5px -10px 20px rgba(255,255,255,0.5); )

Postage Stamp


Using transparent color in gradients, you can create effects like this.

Jpg">