当前位置:网站首页>Linear-gradient()
Linear-gradient()
2022-06-30 09:15:00 【The man of Jike will never admit defeat】
Linear-gradient()
Definition and parameters
linear-gradient()
Function to create an image , This image is in 2 A gradual transition along a straight line between one or more colors .- Do you seem to understand ? Let's start with a piece of code . The generated image is from red - green - Blue - yellow , The direction of change is from top to bottom . The positions of the four colors are 0%,33.3%,66.7%,100% It's about .
background: linear-gradient(red, green, blue, yellow);
Let's see if the parameters of this function are just many colors ?
Edge or corner
: This parameter specifies the color gradient lineStarting point
The location of .( The starting point will be said later )- If the parameter is
edge
, Contains two keywords , And the key words areto
Start .- If the specified color changes horizontally , namely
left
orright
- If the specified color changes in the vertical direction , namely
top
orbottom
- The value of the parameter can be
to top
,to bottom
,to left
,to right
, Converted into angles corresponding to0deg
,180deg
,270deg
,90deg
. perhapsto bottom right
( The lower right ),to top left
( Top left ) etc.
- If the specified color changes horizontally , namely
- If the parameter is
horn
, Just write the angle directly , Remember to bring the unit , Such as45deg
.- More flexible angles , Because using edges can only specify that the color changes horizontally or vertically .
- There must be no spaces between degrees and units !
- Degrees can be negative .
- The degree increases clockwise .
- If the parameter is
color stop
: Consists of a color value , And followed by 1 or 2 Optional end positions . This position can be a percentage value , It can also be the length value along the gradient axis .- example 1
- Let's adjust the position of green in the above figure to 50%, The blue position is adjusted to 75%
background: linear-gradient(red, green 50%, blue 75%, yellow);
- Explain this picture a little , The color changes from red , At the height of the graph 50% Turn green , At the height of the graph 75% Turn blue , In the end in 100% End in yellow .
- example 2
- What happens if we specify an incorrect value ?
background: linear-gradient(red, green 50%, blue 75%, yellow 60%);
- too bad , There is no transition between blue and yellow , Because the logic of the code is blue, it should be in 60% Where the transition is yellow , The yellow and blue ranges overlap , According to the official documents , There is a hard transition between coincident colors .
Subsequent color stops of lower value will override the value of the previous color stop creating a hard transition
- If we follow this wrong practice , We can even draw a rainbow , Think about how to do ? Guessed it , Only two adjacent colors need to coincide in the range !
background: linear-gradient(red 0% 15%, orange 10% 30%, yellow 20% 45%, green 10% 60%, blue 45% 75%, cyan 60% 87%, purple 60% 100%);
- Each color is followed by two percentage parameters , Respectively represent the starting position of the color , And where it ends . Make sure the colors overlap , Just the start position of the back color is before the end position of the front color .
- example 1
color hint
: The third parameter translates literally asColor suggestion
. This is an interpolation hint , Defines two adjacent colors (color-stop
) If the transition between . This parameter is the length value , Determines which of the two color lengths should be the midpoint of the color change . If you ignore , By default, the midpoint of the two color lengths is the midpoint of the color change .background: linear-gradient(red, blue); background: linear-gradient(red, 20%, blue);
- Again , Let's try the given parameter exception , What happens ?
background: linear-gradient(red, -20%, blue); // Blue background: linear-gradient(red, 120%, blue); // Red
form
- One
linear-gradient()
Is written by aAxis
( Color gradient line ) and 2 One or morecolor-stop
Composed of . Every point on this axis is a different color . To smooth the color gradient ,linear-gradient()
Draw a lot of colored lines perpendicular to the axis , The color of each line is the color of the point where the line intersects the axis .- Picture from official website
gradient line
By the gradient image box The midpoint and a role decide . The color of the gradient consists of the start point, the end point and the middle pointcolor stop
decision .Starting point
yesgradient line
Where the first color on the starts .The end point
yesgradient line
Where the last color ends . These two points are related togradient line
Vertical and passing through box Perpendicular to the vertex of the line .The end point
Can be seen asStarting point
About box The mirror point of the midpoint . A slightly more complex definition brings an interesting phenomenon : namely The color of the vertex closest to the start point is the same as the start point . The end point is the same . The following figure ,box The vertex of the upper left corner is the same asStarting point
Same color , Because these two points are on the same line perpendicular togradient line
In a straight line .
- Picture from official website
Browser compatibility
.bcg-gradient { height: 300px; width: 200px; /* opera */ background: -o-linear-gradient(to top, orange, skyblue); /* firefox */ background: -moz-linear-gradient(to top, orange, skyblue); /* safari */ background: -webkit-linear-gradient(to top, orange, skyblue); background: linear-gradient(to top, orange, skyblue); }
- It's on my computer ,IE 9 And previous versions do not support
linear-gradient
function , Novice tutorial say IE 8 And previous versions do not support , Why is this? Please tell me in the comments section .
边栏推荐
- Talk about the job experience of kotlin cooperation process
- Common query and aggregation of ES
- Is it safe to open an account? How can anyone say that it is not reliable.
- asdsadadsad
- Esp32 things (I): Preface
- 关于Lombok的@Data注解
- Small program learning path 1 - getting to know small programs
- 【付费推广】常见问题合集,推荐榜单FAQ
- JVM tuning related commands and explanations
- Handwriting sorter component
猜你喜欢
Metasploit practice - SSH brute force cracking process
使用华为性能管理服务,按需配置采样率
Flutter 0001, environment configuration
维基媒体基金会公布新商业产品“维基媒体企业”首批客户
Duplicate entry '2' for key 'primary appears in JPA‘
Occasionally, Flink data is overstocked, resulting in checkpoint failure
[wechat applet] realize applet pull-down refresh and pull-up loading
Detailed explanation of pytoch's scatter function
Qt连接神通数据库
Talk about the job experience of kotlin cooperation process
随机推荐
Understanding society at the age of 14 - reading notes on "happiness at work"
Flutter theme (skin) changes
Resnet50+fpn for mmdet line by line code interpretation
Esp32 things (3): overview of the overall system design
Maxiouassigner of mmdet line by line interpretation
Six implementation methods of singleton mode
Esp32 things (I): Preface
Handwriting sorter component
Flink SQL custom connector
Rew acoustic test (I): microphone calibration
JVM调优相关命令以及解释
100 lines of code and a voice conversation assistant
Icon resources
Comparison of two ways for C to access SQL Server database (SqlDataReader vs SqlDataAdapter)
Agp7.0|kts makes a reinforced plug-in
2020-11-02
Esp32 (IX): OTA function of function development
asdsadadsad
Detailed explanation of rect class
[cmake] make command cannot be executed normally