CSS Gradient (excerpt)

Source: Internet
Author: User
Tags deprecated

CSS gradients Published: October 24, 2015 11:17:13 posted by: KidWeb Front end design

A css gradient is a newly added type in the CSS3 Image Module <image> . You can use CSS gradients to create smooth gradients between two colors. Instead of a picture, you can speed up the loading time of the page and reduce the bandwidth usage. At the same time, because the gradient is generated directly by the browser, it is better than the picture when the page is scaled, so you can adjust the layout of the page more flexibly and conveniently.

The browser supports two types of gradients: linear gradients (linear), linear-gradient function definitions, and radial gradients (radial), through radial-gradient function definitions.

Linear gradient

In order to create a linear gradient, you need to set a starting point and a gradient effect in one direction (specified as an angle). You'll also define the ending color. The end color is the transition you want gecko to smooth, and you have to specify at least two, and of course you can specify more colors to create more complex gradients.

Simple linear gradient

Here is a linear gradient starting from the middle (horizontal direction) and the top (vertical direction), starting in blue, and transitioning to white.

Screen Live Demo
/* The old syntax, deprecated, but still needed, prefixed, for WebKit-based and old browsers */background: -prefix-linear-gradient(top, blue, white); /* The new syntax needed by standard-compliant browsers (Opera 12.1, IE 10, Fx 16 onwards), without prefix */background: linear-gradient(to bottom, blue, white);

(Viewing the browser Compatibility List overview prefix is necessary to support different browser versions).

Change the same gradient to run from left to right:

Screen Live Demo
/* The old syntax, deprecated, but still needed, prefixed, for WebKit-based and old browsers */background: -prefix-linear-gradient(left, blue, white); /* The new syntax needed by standard-compliant browsers (Opera 12.1, IE 10, Fx 16 onwards), without prefix */background: linear-gradient(to right, blue, white);

(Viewing the browser Compatibility List overview prefix is necessary to support different browser versions).

You can tilt the gradient by specifying the starting position of the parallel and vertical, for example:

Screen Live Demo
/* The old syntax, deprecated, but still needed, prefixed, for WebKit-based and old browsers */background: -prefix-linear-gradient(left top, blue, white); /* The new syntax needed by standard-compliant browsers (Opera 12.1, IE 10, Fx 16 onwards), without prefix */background: linear-gradient(to bottom right, blue, white);
Use angle

If you do not specify an angle, this will automatically be based on the given direction. If you prefer to control the direction of the gradient, you can set a specific angle.

For example, these two gradients, the first direction to the right, and the second with a 70-degree angle.

The one on the right uses this CSS style:

background: linear-gradient(70deg, black, white);

The angle is the angle between the horizontal and the gradient lines, which rotates in a counterclockwise direction. In summary, 0deg creates a vertical gradient from the bottom to the top, creating a horizontal gradient from left to right when it becomes 90deg.

background: linear-gradient(<angle>, red, white);

CSS Gradient (excerpt)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.