简体   繁体   中英

Gradient angle conflict

Hey guys i am working with a simple CSS gradient :

background: linear-gradient(225deg, red 0%, white 10%, #aaaaaa 50%, #cccccc 56%, white 80%);

now look at the below diagram :

在此处输入图片说明

see that the angle 225 deg starts from the bottom-left side corner but however in the CSS example it the top-right corner from where the gradient begins . Why ??

i refered to MDNs docs on gradients and infact the W3c's examples itself are quite good at explaining gradients , but still can't figure this one out .

Thank.

Alexander.

Angles in CSS doesn't have the zero angle at the right, but at the top. Positive angles are clockwise, not counterclockwise.

The settings in the linear gradient doesn't specify where the gradient starts, but the destination of the gradient. Thus, an angle of 225 degrees has the destination in the bottom left corner, so it starts in the top right corner.

The degree means your gradient color goes along the 225 deg. And same as most math theorem, the starting point is (0, 0), the origin point. Starting point denotes 0%, which is red in your css code.

If you want the color started from left-bottom corner to top-right corner, you suppose to apply 45 deg.

Degree also indicates vectors. [1 1]' is 45 deg, which indicates a vector starts from left-bottom to top-right. [-1 -1]' is 225 deg, which indicates a vector starts from top-right to left-bottom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM