Background image linear gradient
Author: m | 2025-04-24
CSS background-image: linear-gradient() CSS background-image Property with linear-gradient Value. To display a linear gradient of colors as background, set CSS background-image property with linear-gradient() value. The syntax of linear-gradient() function is / Copy.
background-image: linear-gradient - CodePen
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
background-image linear-gradient - Codesandbox
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);Background in css with linear-gradient and repeating-linear-gradient
Here are 25 public repositories matching this topic... Code Issues Pull requests 🎨 Tricolor background patterns created using CSS linear and radial gradients. Updated Oct 4, 2020 CSS Code Issues Pull requests Horizontal and vertical examples of responsive Timelines built with the latest Bootstrap 5. Easy to use and customize. Updated Jan 28, 2022 JavaScript Code Issues Pull requests A custom Framework used to add animations and effect to UIButtons. Updated Jan 5, 2022 Swift Code Issues Pull requests Combile Tailwind CSS with AngularJS Updated Dec 29, 2022 TypeScript Code Issues Pull requests 🌈 Create your own css gradient background or generate a random one.😉 Updated Aug 16, 2023 JavaScript Code Issues Pull requests Discussions Facebook gradient background Updated Feb 7, 2023 HTML Code Issues Pull requests This repository contains code for CSS background patterns. Updated Jun 27, 2023 CSS Code Issues Pull requests Template on Next.js with support of axios, API (GET, POST, DELETE). Date default takes from localhost. +Data from Github account 🔐 Updated Jun 17, 2022 JavaScript Code Issues Pull requests Easy way to add beauty background gradient on your websites. If you will like it i'm gonna add more gradient background themes for you 🎨 Updated Feb 21, 2022 SCSS Code Issues Pull requests A custom UIView with an ability to animate a linear gradient layer for a given set of colors. Updated Aug 24, 2019 Objective-C Code Issues Pull requests JavaScript library for creating, animating, and manipulating CSS gradients and background patterns with ease. Updated Jan 31, 2025 JavaScript Code Issues Pull requests Create background gradients for your website using different colors. Updated Aug 17, 2020 JavaScript Code Issues Pull requests Simple colorful gradient background application Updated Apr 26, 2018 Java Code Issues Pull requests Gradient Background Generator using HTML, CSS and JAVASCRIPT Updated Jan 3, 2023 HTML Code Issues Pull requests Randomize custom gradient backgrounds for your websites. Updated Jul 26, 2021 JavaScript Code Issues Pull requests Updated Jun 26, 2020 C# Code Issues Pull requests Simple Animated Gradient Background Example Updated Oct 15, 2018 Java Code Issues Pull requests Modern Bank Application Design with React and Tailwind Updated Feb 11, 2024 JavaScript Code Issues Pull requests Creare uno sfondo sfumato tramite codice Updated Sep 13, 2020 Kotlin Code Issues Pull requests Simple gradient background animation Updated Oct 4, 2018 CSS --> Improve this page Add a description, image, and links to the gradient-background. CSS background-image: linear-gradient() CSS background-image Property with linear-gradient Value. To display a linear gradient of colors as background, set CSS background-image property with linear-gradient() value. The syntax of linear-gradient() function is / Copy. CSS background-image: linear-gradient() CSS background-image Property with linear-gradient Value. To display a linear gradient of colors as background, set CSS background-image property with linear-gradient() value. The syntax of linear-gradient() function is / Copy.How to combine Background Image Linear Gradient in CSS ? Linear
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,html - Background-image with linear-gradient on body not
{ height: 140px; width: 600px; background-color: grey; background-image: repeating-linear-gradient(45deg,grey,pink 7%,orange 10%);}.rg3 { height: 140px; width: 600px; background-color: grey; background-image: repeating-linear-gradient(190deg,grey,pink 7%,orange 12%);}p{ font-size: 22px;}style>head>body>h1>Repeating Linear Gradienth1> p>A repeating gradient starting gray and ending orange:p>div class="rg1">div> p>A repeating gradient on 45deg axe starting gray and ending orange:p>div class="rg2">div> p>A repeating gradient on 190deg axe starting grey and ending orange:p>div class="rg3">div>body>html>Here is the result:Notice all repeating linear gradient images starting grey and finishing orange.Session Replay for DevelopersUncover frustrations, understand bugs and fix slowdowns like never before with OpenReplay — an open-source session replay suite for developers. It can be self-hosted in minutes, giving you complete control over your customer data Happy debugging! Try using OpenReplay today. --> --> Session Replay for Developers Uncover frustrations, understand bugs and fix slowdowns like never before with OpenReplay — an open-source session replay tool for developers. Self-host it in minutes, and have complete control over your customer data. Check our GitHub repo and join the thousands of developers in our community. Radial GradientsA radial gradient is a type of gradient that radiates out from a central point. In terms of visual effects, a radial gradient can create the illusion of three dimensions by adding a sense of deep and perspective to an image. In addition, you can adjust the properties of a radial gradient to control the appearance of the effect, like direction, shape, and size.Examples of some of the properties that you can specify with this function are:ShapeThe shape can be either circular or ellipse. This radial gradient starts from a single point and radiates outward in a circular or elliptical shape.Example of how it works:DOCTYPE html>html>head>style>.ell { height: 245px; width: 200px; background-color: grey; background-image: radial-gradient(grey, pink, orange);}.cir { height: 245px; width: 200px; background-color: grey; background-image: radial-gradient(circle, grey, pink, orange);}style>head>body>h1>Radial Gradient - Shapesh1>h2>Ellipse:h2>div class="ell">div>h2>Circle:h2>div class="cir">div>body>html>HereCSS background-image: linear-gradient() - Examples
Transitions. By defining different colors and their positions, you can create rich, visually appealing effects.Example 1: Gradient with Multiple Stopsbackground-image: radial-gradient(circle, red 10%, yellow 40%, green 70%, blue 100%);This example creates a gradient with four color stops. The transition begins at red, then shifts to yellow at 40%, green at 70%, and finally blue at the edge of the element.Example 2: Gradient with Transparent Colorbackground-image: radial-gradient(circle, rgba(255, 0, 0, 0.5), rgba(0, 0, 255, 0.5));Here, we use semi-transparent colors, allowing the background behind the gradient to subtly show through the colors, creating a more delicate and layered effect.05. Practical Examples of CSS Radial GradientsRadial gradients are used for various effects in modern web design. Below are some practical examples to demonstrate their potential.Example 1: Gradient Backgroundbody { background-image: radial-gradient(circle, #ff7e5f, #feb47b);}This radial gradient creates a soft, circular gradient that transitions from a warm pink to a light orange. It can be used as a beautiful background for websites or web applications.Example 2: Gradient Buttonbutton { background-image: radial-gradient(circle, #ff7e5f, #feb47b); border: none; padding: 10px 20px; color: white; font-size: 16px; cursor: pointer;}This button uses a radial gradient to create a glowing, smooth effect from the center outward, making it stand out and look interactive.Example 3: Gradient Borderdiv { border: 5px solid transparent; background-image: radial-gradient(circle, red, transparent); padding: 20px;}In this example, a transparent border is applied to a div, with the background filling the element with a gradient. The result is a colorful, glowing border effect.06. Combining Radial Gradients with TransparencyJust like with linear gradients, radial gradients can also include transparent colors. This is often used for creating subtle effects or layering content with semi-transparent backgrounds.Example 1: Transparent Radial Gradientbackground-image: radial-gradient(circle, rgba(255, 255, 255, 0.7), rgba(0, 0, 0, 0.7));This gradient fades from a semi-transparent white to a semi-transparent black, often used for overlays or subtle lighting effects.Example 2: Glowing Effect with Transparencybackground-image: radial-gradient(circle, rgba(255, 255, 255, 0.5), rgba(0, 255, 0, 0.8));This creates a glowing effect that starts with a soft white light at the center and transitions to a stronger green color toward the outer edges, suitable for highlighting elements.07. Browser Support and CompatibilityCSS radial gradients are well-supported across all modern browsers, including Chrome, Firefox, Safari, and Edge. However, like linear gradients, older versions of Internet Explorer (IE8 and below) do not support them, so fallback solutions may be needed for those browsers. Chrome: Supported from version 4.0+ Firefox: Supported from version 3.6+ Safari: Supported from version 5.1+ Edge: Supported from version 12+ Internet Explorer: Supported from version 10+08. Best Practices for Using CSS Radial GradientsHere are some best practices to keep in mind when working with CSS radial gradients: Use Gradients Sparingly: Overusing gradients can make a design look cluttered. Use them strategically for emphasis. Combine with Other Effects: Combine radial gradients with box shadows, text shadows, or animations to create more interactive and dynamic elements. Maintain Contrast: Ensure that the colors in your radial gradient provide enough contrast for text or interactive elements to remain legible and accessible. Consider Responsiveness: Test howCombine linear-gradient with dynamic background-image
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ì. CSS background-image: linear-gradient() CSS background-image Property with linear-gradient Value. To display a linear gradient of colors as background, set CSS background-image property with linear-gradient() value. The syntax of linear-gradient() function is / Copy. CSS background-image: linear-gradient() CSS background-image Property with linear-gradient Value. To display a linear gradient of colors as background, set CSS background-image property with linear-gradient() value. The syntax of linear-gradient() function is / Copy.
How to combine Background Image Linear Gradient
Hi lovely readymag users, I was wondering if it is possible to make the background a gradient with custom code? Hi @arizona,Please find below a couple of ways in which to create background gradient using custom code.METHOD 1.We prefer this method as it’s more robust and doesn’t show up as another element on the project settings. It’s also the best method if you wish to have a gradient for every single page. Please note: this will only display upon preview or upon publishing however.Add the following to the of your project. .mag, .mag-pages-container, .container, .page { height: 100vh; width: 100vw; background-image: linear-gradient(180deg, red, yellow); } .page-fixed-bg-container { display: none !important; }METHOD 2.Add in a code injection element and paste in the following code. Click ‘Save & Close’, then under the position options (the small pin icon on the right hand side’ set the it to full width and full height. #background_gradient { height: 100vh; width: 100vw; background-image: linear-gradient(180deg, red, yellow); }I’ve also linked here a test project with two pages to show both methods in action.``background-image: linear-gradient not working in Safari
Download Article Download Article Applying a Gradient|Customizing a Gradient|Video|Q&A When making a slideshow presentation on Google Slides, many people make their backgrounds and textboxes a single solid color. However, creating and using gradients on Google Slides can make your presentation stand out.Go to docs.google.com/presentation/ to create or access a slideshow. If asked, log in by entering your email and password and pressing Login.Advertisement To change the theme of your presentation, click Theme... from the menu bar at the top of the screen.Though this isn't mandatory, choosing a theme other than "Simple Light" and "Simple Dark" will give you more color options for making your gradient. Themes come with assigned colors used throughout them, and when making a gradient, you can use the theme colors to match the rest of your slideshow. This opens up the option to either add an image to or change the color of your background. A drop-down menu will appear, automatically selected in the "Solid" option (unless the theme you chose already had a gradient demo background). The "Solid" page will give you an idea as to what colors you can use for your gradient. Click Gradient next to the pre-selected Solid button at the top of the drop-down menu. This takes you to a page with several multicolored and ombre boxes. You can select these to be the background of your presentation. It shouldn't matter whether you click Custom... or the plus sign underneath it - you should be taken to the same page. A menu will open at the middle of the screen with several options: Type, Angle (if on the linear option) or Center (if on the radial option), Gradient Stops, and Preview, along with a color bar at the bottom. A linear gradient will appear ombre and have colors fade into each. CSS background-image: linear-gradient() CSS background-image Property with linear-gradient Value. To display a linear gradient of colors as background, set CSS background-image property with linear-gradient() value. The syntax of linear-gradient() function is / Copy.Background Image with Linear Gradient Blur - CodePen
Examplecontext.fillStyle=colorSets the color that will be used to fill the interior of the current path.These are color options (these must be quoted):A CSS named color, for example context.fillStyle='red'A hex color, for example context.fillStyle='#FF0000'An RGB color, for example context.fillStyle='rgb(red,green,blue)' where red, green & blue are integers 0-255 indicating the strength of each component color.An HSL color, for example context.fillStyle='hsl(hue,saturation,lightness)' where hue is an integer 0-360 on the color wheel and saturation & lightness are percentages (0-100%) indicating the strength of each component.An HSLA color, for example context.fillStyle='hsl(hue,saturation,lightness,alpha)' where hue is an integer 0-360 on the color wheel and saturation & lightness are percentages (0-100%) indicating the strength of each component and alpha is a decimal value 0.00-1.00 indicating the opacity.You can also specify these color options (these options are objects created by the context):A linear gradient which is a linear gradient object created with context.createLinearGradientA radial gradient which is a radial gradient object created with context.createRadialGradientA pattern which is a pattern object created with context.createPattern body{ background-color:white; } #canvas{border:1px solid red; }window.onload=(function(){ // canvas related variables var canvas=document.getElementById("canvas"); var ctx=canvas.getContext("2d"); // stroke using a CSS color: named, RGB, HSL, etc ctx.fillStyle='red'; ctx.fillRect(50,50,100,50); // stroke using a linear gradient var gradient = ctx.createLinearGradient(225,50,300,50); gradient.addColorStop(0,'red'); gradient.addColorStop(1,'green'); ctx.fillStyle=gradient; ctx.fillRect(200,50,100,50); // stroke using a radial gradient var gradient = ctx.createRadialGradient(100,175,5,100,175,30); gradient.addColorStop(0,'red'); gradient.addColorStop(1,'green'); ctx.fillStyle=gradient; ctx.fillRect(50,150,100,50); // stroke using a pattern var patternImage=new Image(); patternImage.onload=function(){ var pattern = ctx.createPattern(patternImage,'repeat'); ctx.fillStyle=pattern; ctx.fillRect(200,150,100,50); } patternImage.src=' // for demo only, draw labels by each stroke ctx.fillStyle='black'; ctx.textAlign='center'; ctx.textBaseline='middle'; ctx.font='14px arial';Comments
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
2025-04-07How 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-15Color=> #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-02