CSS3 gradient (linear gradient, radial gradient)

Source: Internet
Author: User

Gradient

First, Linear Gradient

1 Linear gradient Format

Linear-gradient ([< starting point > | | < angle;,]? < points;, < points; ...)

Can only be used on the background

2 IE filter:progid:DXImageTransform.Microsoft.gradient (startcolorstr= ' #ffffff ', endcolorstr= ' #ff0000 ', Gradienttype= ' 1 ');

<style>

. Box{width:300px;height:300px;background:-webkit-linear-gradient (Red,blue); Background:-moz-linear-gradient (red , blue); Background:linear-gradient (Red,blue); Filter:progid:DXImageTransform.Microsoft.gradient (startcolorstr= ' Red ', endcolorstr= ' Blue ', gradienttype= ' 0 ');}

</style>

<body>

<divclass= "box" ></div>

</body>

3 Parameters

Starting point: in which direction to start the gradient default: Top

Left, top, left top

From top to bottom

<style>

. Box{width:300px;height:300px;border:10pxsolid #000; background-image:-webkit-linear-gradient (Red,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

Angle: From what angle to start the gradient

The form of xxx deg

Counterclockwise

. Box{width:300px;height:300px;border:10pxsolid #000; background-image:-webkit-linear-gradient (60deg,red,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

Points: color and position of gradient points

Black 50%, location selectable

<style>

. Box{width:300px;height:300px;border:10pxsolid #000; background-image:-webkit-linear-gradient (60deg,red,blue,yellow,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

<style>

. Box{width:300px;height:300px;border:10pxsolid #000; background-image:-webkit-linear-gradient (60deg,red0,blue 50%,green 100%);}

</style>

<body>

<divclass= "box" ></div>

</body>

4 repeating-linear-gradient

<style>

. Box{width:300px;height:300px;border:10pxsolid #000; background-image:-webkit-repeating-linear-gradient (60deg,red0,blue 30px);}

</style>

<body>

<divclass= "box" ></div>

</body>

5 Linear Gradient Instances

Location of the join point

Top, Red 40%,green 60%

Top, Red 50%,green 50%

Two points in the same position--direct jump

You can also use the PX

With Rgba

Top,rgba (255,255,255,1), Rgba (255,255,255,0)

Add background image

Background:-webkit-linear-gradient (Top, Rgba (255,255,255,1) 30%,rgba (255,255,255,0)), url (a.gif)

6 Example 1 : progress bar

<style>

. Wrap{width:200px;height:30px;overflow:hidden;border:1pxsolid #000;}

. box{width:400px;height:30px;background:-webkit-repeating-linear-gradient (15deg,green0,green 10px, #fff 10px, #fff 20px); transition:3s;}

. Wrap:hover. box{margin-left:-100px;}

</style>

<body>

<divclass= "Wrap" >

<divclass= "box" ></div>

</div>

</body>

Mouse over, move to the left to achieve a similar progress bar effect

7 Example 2 : Baidu Music image lighting effect

1.

<style>

. Box{width:300px;height:300px;background:-webkit-linear-gradient ( -30deg,rgba (255,255,255,0) 0,rgba ( 255,255,255,0) 150px,rgba (255,255,255,1) 170px,rgba (255,255,255,1) 180px,rgba (255,255,255,0) 210px) No-repeat,url ( new_bg.png) No-repeat;transition:1s;}

</style>

<body>

<divclass= "box" ></div>

</body>

2.

Mouse over, move up

<style>

. Box{width:300px;height:300px;background:-webkit-linear-gradient ( -30deg,rgba (255,255,255,0) 0,rgba ( 255,255,255,0) 150px,rgba (255,255,255,1) 170px,rgba (255,255,255,1) 180px,rgba (255,255,255,0) 210px) no-repeat- 200px 0, url (new_bg.png) no-repeat; transition:1s;}

. box:hover{background-position:300px0,-100px-100px;}

</style>

<body>

<divclass= "box" ></div>

</body>



Two, radial gradient

Radial-gradient (the beginning of [<;]? [< Shape > | | < size;,]? <, < point;.);

Starting point: Can be a keyword (left,top,right,bottom), specific value or percentage

Shape: Ellipse, Circle

Size: A specific value or percentage, or it can be a keyword (nearest, nearest, farthest, most far corner, contained, or overwritten (Closest-side, Closest-corner,farthest-side, Farthest-corner, contain or cover));

Note Firefox currently supports only keywords

<style>

. box{width:200px;height:200px; Background:-webkit-radial-gradient (Red,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

<style>

. Box{width:200px;height:200px;background:-webkit-radial-gradient (100px50px,red,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

<style>

. Box{width:200px;height:200px;background:-webkit-radial-gradient (100px50px,circle,red,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

<style>

. Box{width:200px;height:200px;background:-webkit-radial-gradient (100px50px,100px 20px,red,blue); background:- Moz-radial-gradient (100px50px,red,blue);}

</style>

<body>

<divclass= "box" ></div>

</body>

Keywords for radial gradients

<style>

. box{width:300px;height:300px;border:1pxsolid #000; float:left;margin:10px;}

. Box:nth-child (1) {background:-webkit-radial-gradient (100px 50px,closest-side,red,blue);}

. Box:nth-child (2) {background:-webkit-radial-gradient (100px 50px,closest-corner,red,blue);}

. Box:nth-child (3) {background:-webkit-radial-gradient (100px 50px,farthest-side,red,blue);}

. Box:nth-child (4) {background:-webkit-radial-gradient (100px 50px,farthest-corner,red,blue);}

. Box:nth-child (5) {background:-webkit-radial-gradient (100px 50px,contain, red,blue);}

. Box:nth-child (6) {background:-webkit-radial-gradient (100px 50px,cover, red,blue);}

</style>

<body>

<divclass= "box" ></div>

<divclass= "box" ></div>

<divclass= "box" ></div>

<divclass= "box" ></div>

<divclass= "box" ></div>

<divclass= "box" ></div>

</body>

CSS3 gradient (linear gradient, radial gradient)

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.