Linear gradient
Author: e | 2025-04-25
The CSS repeating-linear-gradient() function is used to repeat linear gradients. Example: Linear Gradient Repeating Linear Gradient; linear-gradient(red, yellow, blue); repeating-linear
Linear gradient property (linear-gradient) - BrenkoWeb
How they work:Top to Bottom DirectionIt shows a linear gradient that starts at the top and transitions to the bottom.Example:DOCTYPE html>html>head>style>.tb { height: 400px; width: 300px; background-color: grey; background-image: linear-gradient(grey, orange);}p{ font-size: 18px;}style>head>body> h1>Linear Gradient - Top to Bottomh1> p>This linear gradient starts grey at the top, transitioning to orange at the bottom.p>div class="tb">div>body>html>Here is the outcome:Notice that the linear gradient starts grey at the top and transitions to orange at the bottom.Left to Right DirectionIt shows a linear gradient that begins from the left and transitions to the right.Example:DOCTYPE html>html>head>style>.lr { height: 400px; width: 300px; background-color: grey; background-image: linear-gradient(to right, grey , orange);}p{ font-size: 20px;}style>head>body> h1>Linear Gradient - Left to Righth1> p>This linear gradient starts grey at the left, transitioning to orange to the right:p>div class="lr">div>body>html>Here is the result:The linear gradient starts grey on the left, transitioning to orange on the right.Diagonal DirectionA diagonal linear gradient is a gradient that transitions between colors in a diagonal line rather than a horizontal or vertical line.Example:DOCTYPE html>html>head>style>.d { height: 400px; width: 300px; background-color: grey; background-image: linear-gradient(to bottom right, grey, orange);}p{ font-size: 20px;}style>head>body> h1>Linear Gradient - Diagonalh1> p>This linear gradient starts grey at the top left, transitioning to orange at the bottom right:p>div class="d">div>body>html>Here is the result of the code:Notice that the linear gradient starts grey at the top left and transitions to orange at the bottom right.Using AnglesThe Angle gives you more control over a gradient direction by specifying an angle rather than limiting the focus to the bottom, top, right, left, and bottom right. Note that 0deg is equal to the top, 90deg is similar to the right, and 180deg is equal to the bottom.Example:DOCTYPE html>html>head>style>.angle1 { height: 180px; width: 150px; background-color: grey; background-image: linear-gradient(0deg, grey, orange); font-size: 20px;}.angle2 { height: 180px; width: 150px; background-color: grey; background-image: linear-gradient(90deg, grey, orange); 0%, rgba(255,255,255,1) 100%)') }"> const setGradient = () => { setColor('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') }Example toggling gradientType { setColor('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') } const setRadial = () => { setColor('radial-gradient(circle, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') }"> const setLinear = () => { setColor('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') } const setRadial = () => { setColor('radial-gradient(circle, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') }Custom linear-gradient degrees input { let num = parseInt(val) let nans = isNaN(num) ? 0 : num let min = Math.max(nans, 0) let max = Math.min(min, 360) const remaining = value.split(/,(.+)/)[1] setColor(`linear-gradient(${max}deg, ${remaining}`) } return( handleDegrees(e.target.value)} /> )}">import React from 'react'import ColorPicker from 'react-best-gradient-color-picker'function MyApp() { const [color, setColor] = useState('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)'); const degrees = parseInt(value?.split(',')[0]?.split('(')[1]) const handleDegrees = (val) => { let num = parseInt(val) let nans = isNaN(num) ? 0 : num let min = Math.max(nans, 0) let max = Math.min(min, 360) const remaining = value.split(/,(.+)/)[1] setColor(`linear-gradient(${max}deg, ${remaining}`) } return( div> input value={degrees} onChange={(e) => handleDegrees(e.target.value)} /> ColorPicker value={color} onChange={setColor} /> div> )}Roadmapenhanced mobile supportcross browser eye dropper issueenhanced gradient parsing to allow additional gradient typesLicenseCode released under the MIT license.AcknowledgmentsVery special thank you to Rafael Carício for his amazing work parsing gradient strings.Background in css with linear-gradient and repeating-linear-gradient
Font-size: 20px;}.angle3 { height: 180px; width: 150px; background-color: grey; background-image: linear-gradient(180deg, grey, orange); font-size: 20px;}style>head>body>h1>Linear Gradients - Using Different Anglesh1>div class="angle1"style="text-align:center;">0degdiv>br>div class="angle2"style="text-align:center;">90degdiv>br>div class="angle3"style="text-align:center;">180degdiv>br>body>html>Here is the outcome:Notice the first image has orange background color at the top because 0deg is equal to the top, and the second image has orange background color at the right because 90deg is similar to the right. Finally, the third image has orange background color at the bottom because 180deg is equal to the bottom.Using Multiple Color StopsThe multiple color stops demonstrate a linear gradient from top to bottom. In addition, you can use it to create gradients that transition between more than two colors.Example:DOCTYPE html>html>head>style>.mc { height: 500px; width: 400px; background-color: gray; background-image: linear-gradient(grey, pink,silver, orange,green);}style>head>body> h1>Linear Gradients - Multiple Color Stopsh1>div class="mc">div>body>html>Here is the outcome:Using TransparencyYou can use gradient transparency to create fading gradient effects. In addition, the clarity of the image or element varies depending on the colors in the gradient. Finally, to add transparency, use the rgba() process to explain the color stops. For instance, the value of the rgba() function in the last parameter could be from 0 to 1, which explains the color’s transparency 0 indicates full transparency, and 1 shows full color (no transparency).For example:DOCTYPE html>html>head>style>.t { height: 400px; background-image: linear-gradient(to right, rgba(128,128,128,1), rgba(128,128,128,0));}style>head>body>h1>Linear Gradient - Transparencyh1>div class="t">div>body>html>Here is the result:Notice the linear gradient starts fully transparent from the right and transitions to full grey color.Repeating a linear-gradientTo repeat a linear gradient, you can use the repeating-linear-gradient() function in CSS. This function is the same as the linear-gradient() function but repeats the gradient pattern along the direction you specify.Let us see an example of how to use the repeating-linear-gradient() function to create a repeating gradient:DOCTYPE html>html>head>style>.rg1 { height: 140px; width: 600px; background-color: grey; background-image: repeating-linear-gradient(gray, pink 10%, orange 20%);}.rg2. The CSS repeating-linear-gradient() function is used to repeat linear gradients. Example: Linear Gradient Repeating Linear Gradient; linear-gradient(red, yellow, blue); repeating-linear The CSS repeating-linear-gradient() function is used to repeat linear gradients. Example: Linear Gradient Repeating Linear Gradient; linear-gradient(red, yellow, blue); repeating-linearThe repeating-linear-gradient function - a repeating linear gradient
Color=> #37cdff> rgba(color, 0.5)=> rgba(55,205,255,0.5)$ stylus -i> color = white=> #fff> color - rgb(200,50,0)=> #37cdff> color=> #fff> color -= rgb(200,50,0)=> #37cdff> color=> #37cdff> rgba(color, 0.5)=> rgba(55,205,255,0.5)Resolving relative urls inside imports By default Stylus don't resolve the urls in imported .styl files, so if you'd happen to have a foo.styl with @import "bar/bar.styl" which would have url("baz.png"), it would be url("baz.png") too in a resulting CSS.But you can alter this behavior by using --resolve-url (or just -r) option to get url("bar/baz.png") in your resulting CSS.List dependencies You can use --deps (or just -D) flag to get a list of dependencies of the compiled file.For example, suppose we have test.styl:@import 'foo'@import 'bar'@import 'foo'@import 'bar'And inside foo.styl:@import 'baz'@import 'baz'Running:$ stylus --deps test.styl$ stylus --deps test.stylWill give us list of the imports paths:foo.stylbaz.stylbar.stylfoo.stylbaz.stylbar.stylNote that currently this does not works for dynamically generated paths.Utilizing Plugins For this example we'll use the nib Stylus plugin to illustrate its CLI usage.Suppose we have the following Stylus, which imports nib to use its linear-gradient() function.@import 'nib'body background: linear-gradient(20px top, white, black)@import 'nib'body background: linear-gradient(20px top, white, black)Our first attempt to render using stylus(1) via stdio might look like this:$ stylus test.styl$ stylus test.stylWhich would yield the following error (because Stylus doesn't know where to find nib).Error: stdin:3 1| 2|> 3| @import 'nib' 4| 5| body 6| background: linear-gradient(20px top, white, black)Error: stdin:3 1| 2|> 3| @import 'nib' 4| 5| body 6| background: linear-gradient(20px top, white, black)For plugins that simply supply Stylus APIs, we could add the path to the Stylus lookup paths. We do so by using the --include or -I flag:$ stylus test.styl --include ../nib/lib$ stylus test.styl --include ../nib/libNow yielding the output below. (As you might notice, calls to gradient-data-uri() and create-gradient-image() output as literals. This is because exposing the library path isn't enough when a plugin provides a JavaScript API. However, if we only wanted to use pure-Stylus nib functions, we'd be fine.)body { background: url(gradient-data-uri(create-gradient-image(20px, top))); background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #000)); background: -webkit-linear-gradient(top, #fff 0%, #000 100%); background: -moz-linear-gradient(top, #fff 0%, #000 100%); background: linear-gradient(top, #fff 0%, #000 100%);}body { background: url(gradient-data-uri(create-gradient-image(20px, top))); background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #000)); background: -webkit-linear-gradient(top, #fff 0%, #000 100%); background: -moz-linear-gradient(top, #fff 0%, #000 100%); background: linear-gradient(top, #fff 0%, #000 100%);}So, what we need to do is use the --use, or -u flag. It expects a path to a node module (with or without the .js extension). This require()s the module, expecting a function to be exported as module.exports, which then calls style.use(fn()) to expose the plugin (defining its js functions, etc.).$ stylus test.styl --use ../nib/lib/nib$ stylus test.styl --use ../nib/lib/nibYielding the expected result:body { background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAUCAYAAABMDlehAAAABmJLR0QA/wD/AP+gvaeTAAAAI0lEQVQImWP4+fPnf6bPnz8zMH358oUBwkIjKJBgYGNj+w8Aphk4blt0EcMAAAAASUVORK5CYII="); background: -webkit-gradient(linear, left top, Bên trái: nền: ## 901A1C; background-image: -moz-linear-gradient (phía trên bên phải, # 901A1C 0%, # FFFFFF 100%); background-image: -webkit-gradient (tuyến tính, đỉnh phải, đáy trái, màu dừng (0, # 901A1C), màu dừng (1, #FFFFFF)); nền: -webkit-linear-gradient (phải trên cùng, # 901A1C 0%, #ffffff 100%); background: -o-linear-gradient (phía trên bên phải, # 901A1C 0%, #ffffff 100%); nền: -ms-linear-gradient (phía trên bên phải, # 901A1C 0%, #ffffff 100%); nền: linear-gradient (phải trên cùng, # 901A1C 0%, #ffffff 100%); Bạn có thể nhận thấy rằng không có bộ lọc IE nào trong ví dụ này. Đó là bởi vì IE chỉ cho phép hai loại bộ lọc: từ trên xuống dưới (mặc định) và từ trái sang phải (với công tắc GradientType = 1). Xem gradient tuyến tính chéo này trong hành động chỉ sử dụng CSS. 03 trên 04 Dừng màu Một gradient với ba điểm dừng màu. J Kyrnin Với gradient tuyến tính CSS3, bạn có thể thêm nhiều màu sắc cho gradient của mình để tạo ra hiệu ứng thậm chí còn đẹp hơn. Để thêm các màu này, bạn thêm các màu bổ sung vào cuối thuộc tính của mình, được phân tách bằng dấu phẩy. Bạn nên bao gồm nơi trên dòng màu sắc nên bắt đầu hoặc kết thúc là tốt. Bộ lọc Internet Explorer chỉ hỗ trợ hai điểm dừng màu, vì vậy khi bạn tạo gradient này, bạn chỉ nên bao gồm màu đầu tiên và thứ hai mà bạn muốn hiển thị. Đây là CSS cho gradient 3 màu ở trên: nền: #ffffff; nền: -moz-linear-gradient (bên trái, #ffffff 0%, # 901A1C 51%, #ffffff 100%); background: -webkit-gradient (tuyến tính, đầu trái, phải trên cùng, màu dừng (0%, # ffffff), màu dừng (51%, # 901A1C), dừng màu (100%, # ffffff)); nền: -webkit-linear-gradient (bên trái, #ffffff 0%, # 901A1C 51%, # ffffff 100%); background: -o-linear-gradient (bên trái, #ffffff 0%, # 901A1C 51%, # ffffff 100%); nền: -ms-linear-gradient (bên trái, #ffffff 0%, # 901A1C 51%, # ffffff 100%); bộ lọc: progid: DXImageTransform.Microsoft.gradient (startColorstr = '# ffffff', endColorstr = '# ffffff', GradientType = 1); background: gradient tuyến tính (trái, #ffffff 0%, # 901A1C 51%, # ffffff 100%); Xem gradient tuyến tính này với ba điểm dừng màu trong hành động chỉ bằng CSS. 04/04 Làm cho tòa nhà Gradients dễ dàng hơn Trình tạo Gradient CSS cuối cùng. ảnh chụp màn hình bởi J Kyrnin lịch sự ColorZilla Có hai trang web tôi khuyên bạn nên giúp bạn xây dựng gradient, mỗi trang web đều có những lợi ích và hạn chế đối với họ, tôi chưa tìm thấy trình tạo gradient làm mọi thứ. Trình tạo Gradient CSS cuối cùng Trình tạo gradient này rất phổ biến vìUSS gradients (linear-gradient) and image gradients
Name for the SVG gradient. Other elements inside the file can reference it. The gradient can be applied for the fill or stroke properties for shapes, text, etc.SVG Linear GradientWhen talking about the SVG gradient, we have to define what a gradient vector is? The linear gradient vector connects starting and ending points onto which the gradient stops are mapped. The attributes x1, y1, x2 and y2 set the linear gradient vector. Their values can be either numbers or percentages.The has nested children elements that control the colors used in the gradient. Each color is specified with the tag. An offset attribute of the element indicates where the gradient stop is placed. For linear gradients, it represents a location along the gradient vector (linear-gradient.svg). 1svg height="250" width="700" xmlns=" 2 defs> 3 linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%"> 4 stop offset="10%" style="stop-color:LIGHTSALMON" /> 5 stop offset="50%" style="stop-color:TEAL" /> 6 stop offset="90%" style="stop-color:LIGHTPINK" /> 7 linearGradient> 8 defs> 9 ellipse cx="300" cy="170" rx="165" ry="55" fill="url(#grad1)" />10 text x="10" y="85" font-family="Arial" stroke="grey" stroke-width="1" font-size="90" fill="url(#grad1)" >Linear Gradienttext>11svg>In the example above, the linear gradient id="grad1" is referenced by the and elements in the fill attribute. There are three nodes inside the linear gradient. In each of them, an offset attribute sets the position the SVG gradient gets a stop-color value.SVG Radial GradientA radial gradient is more difficult than a linear one. The colors change circularly rather than linearly in it. The attributes cx, cy, and r define the outermost circle for the radial gradient: cx and cy mark the center of this circle. Their values are specified as percentages of the width and height of a shape to fill. Both defaults to 50% if omitted. The fx and fy attributes define the innermost circle for the radial gradient. This is the point at which the SVG gradient «radiates».In this example, the centers of the innermost and outermost border of the SVG gradient are the same (radial-gradient.svg). 1svg height="300" width="600" xmlns=" 2 defs> 3 radialGradient id="myRG" cx="0.5" cy="0.5" r="0.9" fx="0.5" fy="0.5" spreadMethod="pad"> 4 stop offset="0%" stop-color="BISQUE" /> 5 stop offset="60%" stop-color="CADETBLUE" /> 6 radialGradient> 7 defs> 8 ellipse cx="300" cy="170" rx="165" ry="55" fill="url(#myRG)" /> 9 text x="10" y="85" font-family="Arial" stroke="grey" stroke-width="1" font-size="85" fill="url(#myRG)" >Radial Gradienttext>10svg>Let’s see an example of the radial gradient, where the focal point (fx, fy) moved from the center of the object to position fx=25% and fy=25% (radial-gradient1.svg): 1svg height="300" width="600" xmlns=" 2 defs> 3 radialGradient id="myRG" cx="0.5" cy="0.5" r="0.8" fx="25%" fy="25%" spreadMethod="pad"> 4 stop offset="0%" stop-color="BISQUE" /> 5 stop offset="30%" stop-color="SILVER" /> 6 stop offset="60%" stop-color="BISQUE" /> 7 stop offset="90%" stop-color="GREY" /> 8 radialGradient> 9 defs>10 ellipse cx="300" cy="170" rx="185" ry="65" fill="url(#myRG)" fill-opacity="1" />11 text x="10" y="85" font-family="Arial" stroke="grey" stroke-width="1" font-size="85"react-native-linear-gradient/react-native-linear-gradient
And the gradient direction is defined using the linear-gradient() function. Therefore, linear gradients can add visual interest to a page or create a sense of depth or movement.Radial gradients: A radial gradient ****is a type of gradient that radiates outwards from a central point. Its created by specifying two or more colors that blend at a central point and then spread outwards in a circular or elliptical pattern. You can use radial gradients to create various visual effects, including the illusion of depth, adding emphasis to a particular area, or creating a sense of motion.Conic gradients: A conic gradient is a color gradient that creates a circular pattern, with the colors radiating outward from the center in a conical shape. The conic gradient allows for circular color schemes, which can help create visually striking and unique designs. You must define at least two colors in other to create a conic gradient.In CSS, gradients are generally one color that fades into another, which lets you control every aspect, from the beginning, a direction and the shape to the colors and how they change from one color to another.In the following sections, we’ll discuss examples of different gradients.Linear GradientsThe linear gradient effect is a color transition that goes from one color to another in a straight line. Therefore, you can use this effect to add depth or movement to an element on a webpage. You can use several properties to control the appearance of a linear gradient effect, including:The direction, which determines the Angle at which the gradient transition occurs,The starting and ending colors, which determine the colors at either end of the gradient,The stop points determine where the transition between colors begins and ends.The shape of the gradient transition,The size of the gradient.Here are the examples of linear gradient properties and. The CSS repeating-linear-gradient() function is used to repeat linear gradients. Example: Linear Gradient Repeating Linear Gradient; linear-gradient(red, yellow, blue); repeating-linearLinear Gradient CSS Repeating Linear Gradient CSS - YouTube
Can add as many color stops as you want to create different linear gradient effects.To work with linear gradient, mind the following:Angle: Set the angle of direction for the gradient line. By default, a linear gradient runs horizontally from left to right with an angle of 0 degree. 90 degrees creates a top-to-bottom vertical gradient. As the degree increases, the gradient direction rotates clockwise.Offset X (%, range from -100 to 100): Drag the Offset X slider to the right or left to change the position of gradient stops horizontally. Or, use the Offset X spin box to do that. Scale X (%, range from 10 to 250): Drag the Scale X slider to the right or left to change the width of gradient colors. When the value is “10”, the width of gradient colors is minimum. When the value is “250”, this value is maximum. Gradient strip (3): Display a “live” sample of the gradient. Use it to make visual changes to the gradient.Color stop: Each color stop on the strip is a distinct color. The selected color stop has a blue border (4). To add a color stop, click on the strip or click the Add button. Or, click the Remove button to delete a selected color stop.Position (%): Specify the position of a color stop, where you want to color to start. Or drag the color stops along the strip to do that. By default, the starting and ending color stop has a position of 0% and 100% respectively.Color: Define a color for each color stop.Opacity: Change the opacity level of color stops.Radial GradientLike linear gradients, radial gradients also create a gradual blending between two or more colors. But this gradient style radiates from its center.To work with radial gradient, select Radial from the Gradient Style box (5).MindComments
How they work:Top to Bottom DirectionIt shows a linear gradient that starts at the top and transitions to the bottom.Example:DOCTYPE html>html>head>style>.tb { height: 400px; width: 300px; background-color: grey; background-image: linear-gradient(grey, orange);}p{ font-size: 18px;}style>head>body> h1>Linear Gradient - Top to Bottomh1> p>This linear gradient starts grey at the top, transitioning to orange at the bottom.p>div class="tb">div>body>html>Here is the outcome:Notice that the linear gradient starts grey at the top and transitions to orange at the bottom.Left to Right DirectionIt shows a linear gradient that begins from the left and transitions to the right.Example:DOCTYPE html>html>head>style>.lr { height: 400px; width: 300px; background-color: grey; background-image: linear-gradient(to right, grey , orange);}p{ font-size: 20px;}style>head>body> h1>Linear Gradient - Left to Righth1> p>This linear gradient starts grey at the left, transitioning to orange to the right:p>div class="lr">div>body>html>Here is the result:The linear gradient starts grey on the left, transitioning to orange on the right.Diagonal DirectionA diagonal linear gradient is a gradient that transitions between colors in a diagonal line rather than a horizontal or vertical line.Example:DOCTYPE html>html>head>style>.d { height: 400px; width: 300px; background-color: grey; background-image: linear-gradient(to bottom right, grey, orange);}p{ font-size: 20px;}style>head>body> h1>Linear Gradient - Diagonalh1> p>This linear gradient starts grey at the top left, transitioning to orange at the bottom right:p>div class="d">div>body>html>Here is the result of the code:Notice that the linear gradient starts grey at the top left and transitions to orange at the bottom right.Using AnglesThe Angle gives you more control over a gradient direction by specifying an angle rather than limiting the focus to the bottom, top, right, left, and bottom right. Note that 0deg is equal to the top, 90deg is similar to the right, and 180deg is equal to the bottom.Example:DOCTYPE html>html>head>style>.angle1 { height: 180px; width: 150px; background-color: grey; background-image: linear-gradient(0deg, grey, orange); font-size: 20px;}.angle2 { height: 180px; width: 150px; background-color: grey; background-image: linear-gradient(90deg, grey, orange);
2025-04-100%, rgba(255,255,255,1) 100%)') }"> const setGradient = () => { setColor('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') }Example toggling gradientType { setColor('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') } const setRadial = () => { setColor('radial-gradient(circle, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') }"> const setLinear = () => { setColor('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') } const setRadial = () => { setColor('radial-gradient(circle, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)') }Custom linear-gradient degrees input { let num = parseInt(val) let nans = isNaN(num) ? 0 : num let min = Math.max(nans, 0) let max = Math.min(min, 360) const remaining = value.split(/,(.+)/)[1] setColor(`linear-gradient(${max}deg, ${remaining}`) } return( handleDegrees(e.target.value)} /> )}">import React from 'react'import ColorPicker from 'react-best-gradient-color-picker'function MyApp() { const [color, setColor] = useState('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)'); const degrees = parseInt(value?.split(',')[0]?.split('(')[1]) const handleDegrees = (val) => { let num = parseInt(val) let nans = isNaN(num) ? 0 : num let min = Math.max(nans, 0) let max = Math.min(min, 360) const remaining = value.split(/,(.+)/)[1] setColor(`linear-gradient(${max}deg, ${remaining}`) } return( div> input value={degrees} onChange={(e) => handleDegrees(e.target.value)} /> ColorPicker value={color} onChange={setColor} /> div> )}Roadmapenhanced mobile supportcross browser eye dropper issueenhanced gradient parsing to allow additional gradient typesLicenseCode released under the MIT license.AcknowledgmentsVery special thank you to Rafael Carício for his amazing work parsing gradient strings.
2025-04-06Font-size: 20px;}.angle3 { height: 180px; width: 150px; background-color: grey; background-image: linear-gradient(180deg, grey, orange); font-size: 20px;}style>head>body>h1>Linear Gradients - Using Different Anglesh1>div class="angle1"style="text-align:center;">0degdiv>br>div class="angle2"style="text-align:center;">90degdiv>br>div class="angle3"style="text-align:center;">180degdiv>br>body>html>Here is the outcome:Notice the first image has orange background color at the top because 0deg is equal to the top, and the second image has orange background color at the right because 90deg is similar to the right. Finally, the third image has orange background color at the bottom because 180deg is equal to the bottom.Using Multiple Color StopsThe multiple color stops demonstrate a linear gradient from top to bottom. In addition, you can use it to create gradients that transition between more than two colors.Example:DOCTYPE html>html>head>style>.mc { height: 500px; width: 400px; background-color: gray; background-image: linear-gradient(grey, pink,silver, orange,green);}style>head>body> h1>Linear Gradients - Multiple Color Stopsh1>div class="mc">div>body>html>Here is the outcome:Using TransparencyYou can use gradient transparency to create fading gradient effects. In addition, the clarity of the image or element varies depending on the colors in the gradient. Finally, to add transparency, use the rgba() process to explain the color stops. For instance, the value of the rgba() function in the last parameter could be from 0 to 1, which explains the color’s transparency 0 indicates full transparency, and 1 shows full color (no transparency).For example:DOCTYPE html>html>head>style>.t { height: 400px; background-image: linear-gradient(to right, rgba(128,128,128,1), rgba(128,128,128,0));}style>head>body>h1>Linear Gradient - Transparencyh1>div class="t">div>body>html>Here is the result:Notice the linear gradient starts fully transparent from the right and transitions to full grey color.Repeating a linear-gradientTo repeat a linear gradient, you can use the repeating-linear-gradient() function in CSS. This function is the same as the linear-gradient() function but repeats the gradient pattern along the direction you specify.Let us see an example of how to use the repeating-linear-gradient() function to create a repeating gradient:DOCTYPE html>html>head>style>.rg1 { height: 140px; width: 600px; background-color: grey; background-image: repeating-linear-gradient(gray, pink 10%, orange 20%);}.rg2
2025-04-24Color=> #37cdff> rgba(color, 0.5)=> rgba(55,205,255,0.5)$ stylus -i> color = white=> #fff> color - rgb(200,50,0)=> #37cdff> color=> #fff> color -= rgb(200,50,0)=> #37cdff> color=> #37cdff> rgba(color, 0.5)=> rgba(55,205,255,0.5)Resolving relative urls inside imports By default Stylus don't resolve the urls in imported .styl files, so if you'd happen to have a foo.styl with @import "bar/bar.styl" which would have url("baz.png"), it would be url("baz.png") too in a resulting CSS.But you can alter this behavior by using --resolve-url (or just -r) option to get url("bar/baz.png") in your resulting CSS.List dependencies You can use --deps (or just -D) flag to get a list of dependencies of the compiled file.For example, suppose we have test.styl:@import 'foo'@import 'bar'@import 'foo'@import 'bar'And inside foo.styl:@import 'baz'@import 'baz'Running:$ stylus --deps test.styl$ stylus --deps test.stylWill give us list of the imports paths:foo.stylbaz.stylbar.stylfoo.stylbaz.stylbar.stylNote that currently this does not works for dynamically generated paths.Utilizing Plugins For this example we'll use the nib Stylus plugin to illustrate its CLI usage.Suppose we have the following Stylus, which imports nib to use its linear-gradient() function.@import 'nib'body background: linear-gradient(20px top, white, black)@import 'nib'body background: linear-gradient(20px top, white, black)Our first attempt to render using stylus(1) via stdio might look like this:$ stylus test.styl$ stylus test.stylWhich would yield the following error (because Stylus doesn't know where to find nib).Error: stdin:3 1| 2|> 3| @import 'nib' 4| 5| body 6| background: linear-gradient(20px top, white, black)Error: stdin:3 1| 2|> 3| @import 'nib' 4| 5| body 6| background: linear-gradient(20px top, white, black)For plugins that simply supply Stylus APIs, we could add the path to the Stylus lookup paths. We do so by using the --include or -I flag:$ stylus test.styl --include ../nib/lib$ stylus test.styl --include ../nib/libNow yielding the output below. (As you might notice, calls to gradient-data-uri() and create-gradient-image() output as literals. This is because exposing the library path isn't enough when a plugin provides a JavaScript API. However, if we only wanted to use pure-Stylus nib functions, we'd be fine.)body { background: url(gradient-data-uri(create-gradient-image(20px, top))); background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #000)); background: -webkit-linear-gradient(top, #fff 0%, #000 100%); background: -moz-linear-gradient(top, #fff 0%, #000 100%); background: linear-gradient(top, #fff 0%, #000 100%);}body { background: url(gradient-data-uri(create-gradient-image(20px, top))); background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #000)); background: -webkit-linear-gradient(top, #fff 0%, #000 100%); background: -moz-linear-gradient(top, #fff 0%, #000 100%); background: linear-gradient(top, #fff 0%, #000 100%);}So, what we need to do is use the --use, or -u flag. It expects a path to a node module (with or without the .js extension). This require()s the module, expecting a function to be exported as module.exports, which then calls style.use(fn()) to expose the plugin (defining its js functions, etc.).$ stylus test.styl --use ../nib/lib/nib$ stylus test.styl --use ../nib/lib/nibYielding the expected result:body { background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAUCAYAAABMDlehAAAABmJLR0QA/wD/AP+gvaeTAAAAI0lEQVQImWP4+fPnf6bPnz8zMH358oUBwkIjKJBgYGNj+w8Aphk4blt0EcMAAAAASUVORK5CYII="); background: -webkit-gradient(linear, left top,
2025-04-23