Efficient CSS development practices: CSS 3, LESS, SASS, Bootstrap, Foundation-Reading Notes (3) linear gradient

Source: Internet
Author: User

Efficient CSS development practices: CSS 3, LESS, SASS, Bootstrap, Foundation-Reading Notes (3) linear gradient

Linear gradient can be set with three parameter values: direction, start color, and end color. In the simplest mode, you only need to define the start color and end color. The start, end, and direction are from the top to the bottom of the element by default. The following is an example:

.test{  background:linear-gradient(red, blue);}

The result of the above Code is 5.9.


Figure 5.9 simplest linear gradient effect

If you want to display the 5.9 Effect in some earlier versions of browsers (except IE), you need to add the compatible code:

. Test {background:-webkit-linear-gradient (red, blue);/* Core webkit browser compatible Code */background:-o-linear-gradient (red, blue ); /* Opera Browser compatible Code */background:-moz-linear-gradient (red, blue);/* Firefox browser compatible Code */background: linear-gradient (red, blue ); /* The standard syntax should be placed at the end */}

Linear gradient can specify the gradient direction, as shown in the following example:

. Test {background:-webkit-linear-gradient (left, red, blue);/* Core webkit browser compatible Code */background:-o-linear-gradient (left, red, blue);/* operabrowser compatible Code */background:-moz-linear-gradient (left, red, blue);/* Firefox browser compatible Code */background: linear-gradient (to right, red, blue);/* The standard syntax should be placed at the end */}

The effect of the above Code is 5.10. After the left/to right parameter is set, the gradient direction changes from top to bottom to from left to right.


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature/Signature + PC9wPgo8cD69pbHkt73P8ru5v8nS1Mq508O9x7bIwLSx7cq + Signature = "brush: java;">. test {background:-webkit-linear-gradient (45deg, red, blue);/* Core webkit browser compatible Code */background:-o-linear-gradient (45deg, red, blue);/* operabrowser compatible Code */background:-moz-linear-gradient (45deg, red, blue);/* Firefox browser compatible Code */background: linear-gradient (45deg, red, blue);/* standard syntax */}
The effect is 5.11.


Figure 5.11 specify the gradient direction to 45 °

Linear gradient not only supports gradient of two colors, but also can add any color. For example, you can use linear gradient to construct a rainbow effect, as shown in Figure 5.12.


Figure 5.12 rainbow color

The rainbow effect code shown in Figure 5.12 is as follows:

.test {  background:-webkit-linear-gradient(left,red,orange,yellow,green,blue,indigo,violet);  background:-o-linear-gradient(left,red,orange,yellow,green,blue,indigo,violet);  background:-moz-linear-gradient(left,red,orange,yellow,green,blue,indigo,violet);  background:linear-gradient(to right, red,orange,yellow,green,blue,indigo,violet);}

Exchange with others




Related Article

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.