当前位置:网站首页>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 pointThe location of .( The starting point will be said later )- If the parameter is
edge, Contains two keywords , And the key words aretoStart .- If the specified color changes horizontally , namely
leftorright - If the specified color changes in the vertical direction , namely
toporbottom - 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-stopComposed 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 lineBy 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 stopdecision .Starting pointyesgradient lineWhere the first color on the starts .The end pointyesgradient lineWhere the last color ends . These two points are related togradient lineVertical and passing through box Perpendicular to the vertex of the line .The end pointCan be seen asStarting pointAbout 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 pointSame color , Because these two points are on the same line perpendicular togradient lineIn 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-gradientfunction , Novice tutorial say IE 8 And previous versions do not support , Why is this? Please tell me in the comments section .
边栏推荐
- ES6 learning road 5 symbol
- Coredata acquisition in swift sorting, ascending, descending
- Opencv learning notes -day 12 (ROI region extraction and inrange() function operation)
- Detectron2 source code reading 3-- encapsulating dataset with mapper
- Metasploit practice - SSH brute force cracking process
- Mmdet line by line deltaxywhbboxcoder
- Introduction to MySQL foundation power node [Lao Du] class assignment
- Talk about writing
- CUDA realizes matrix multiplication
- Flutter 0001, environment configuration
猜你喜欢

Flink Exception -- No ExecutorFactory found to execute the application

Deep understanding of continuation principle

Do you want the dialog box that pops up from the click?

Explanation on the use of password profiteering cracking tool Hydra

Flink SQL custom connector

Opencv learning notes-day6-7 (scroll bar operation demonstration is used to adjust image brightness and contrast, and createtrackbar() creates a scroll bar function)

Qt连接神通数据库

Rew acoustic test (III): generate test signal

Interpretation of source code demand:a rotation equivariant detector for aerial object detection

Wechat development tool (applet)
随机推荐
[untitled]
Flink SQL custom connector
How can I get the discount for opening a securities account? Is online account opening safe?
Opencv learning notes -day 11 (split() channel separation function and merge() channel merge function)
Opencv learning notes -day1 (image reading display imread, imshow, namedwindow)
Detailed explanation of rect class
Detectron2 source code reading 4-- registrar construction model
Esp32 (6): Bluetooth and WiFi functions for function development
Use Huawei performance management service to configure the sampling rate on demand
Sort (simple description)
Get to know handler again
Pytorch BERT
Splice and slice functions of JS
Do you want the dialog box that pops up from the click?
mysql基础入门 day4 动力节点[老杜]课堂笔记
Interpretation of orientedrcnn papers
[data analysis and display]
RPC understanding
Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
Unsupportedclassversionerror is reported when starting jar package. How to repair it