You can also use angles, to be more accurate in specifying the direction of the gradient: background: linear-gradient(angle, colour-stop1, colour-stop2) Here’s a sample for a gradient starting from the top-left: background: linear-gradient(to bottom right, red, yellow) Using angles to specify the direction of the gradient You can also transition a gradient diagonally by specifying the horizontal and vertical starting positions, for example, top-left, or bottom-right. To make it left to right, you add an additional parameter at the beginning of the linear-gradient() starting with the word to which indicates the direction: background: linear-gradient(to right, red, yellow) Examples Top to bottom: background: linear-gradient(red, yellow) If no direction is specified, the default transition is top to bottom. background: linear-gradient(direction, colour-stop1, colour-stop2. It is declared on either the background or background-image properties. They are the colors the transitions are created among. To create a linear gradient you must define at least two color stops. A linear gradient with two color stops Syntax In a linear gradient, the colors flow in a single direction, for example from left to right, top to bottom, or any angle you choose. We could have written this in several other ways, all of which are valid. …where it is assumed that the location of the gradient starts at the very center of the element ( 50% 50%) and is evenly distributed between the twi color values. Any color value is accepted here, including hex, named, RGB and HSL. color-stop: These are color values that define the gradient.We can also specify an exact position using a numeric value, including percentage, all of which are relative to the element’s bounding box. That means top, right, left, and center all work here, as well as combinations where two named values (e.g. position: This works very much the same way that it does on background-position.Again, negative values are a no-no, but percentages are fair game since the size is relative to the gradient box rather than the element. or percentage: A second numeric value can be provided to declare the explicit size of an ellipse, but not a circle.Sorry, no negative units or percentages allowed because a negative circle would be vacuum and percentages can be relative to any number of surrounding values. This has to be stated in positive pixels or relative units. radius: We can specify a numeric value that serves as the circle’s radius.farthest-corner: The opposite of closest-corner, where the gradient ends at the corner that is located furthest from the shape’s center.closest-corner: The gradient will end at the corner that matches as the closest to the shape’s center.farthest-side (default): The opposite of closest-side, where the gradient will end at the side furthest from the shape’s center.If two sides match this criteria, then it will be evenly distributed. closest-side: The gradient will end at side closest to the center of the shape.This can be expressed by name or an exact measure of length. size: Influences the ending shape of the gradient by taking the shape value and instructing where the gradient should end based on the center of the shape.For example, an element that is a perfect square would be a great match for circle whereas anything rectangular is ripe for ellipse. We can omit this value and the notation will measure the element’s side lengths to determine whether one value better matches the situation. Since we’re talking about radial gradients, the shapes are limited to being circular in nature. shape: Determines the shape of the gradient follows when transitioning outward, from one color to the next.The radial-gradient notation accepts the following values:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |