• 0

[CSS] Gradient border with three colours?


Question

Hi all.

 

I've been googling around and found many tutorials which show how to create a css border gradient with 2 colours but none with 3.

 

http://jsfiddle.net/MJhuw/

 

That's as far as I can get, I'd like to have it fade back to the original.

 

Many thanks.

 

 

7 answers to this question

Recommended Posts

  • 0

.left-to-right {
    border-width: 0 0 3px 0;
    -webkit-border-image: 
        -webkit-gradient(linear, 100% 0, 0 0, from(#4cd964), to(#4cd964), color-stop( 50%, #007aff)) 100% 1;
}

From() defines the color at the start, so the border starts with the color #4CD964.

To() defines the color at the end, so the border end with the color #4CD964.

Color-stop() defines a color somewhere inbetween the start and end. You can use more color-stops to add more colors to the gradient, the first value of color-stop defines the location, in this case 50% of the length of the border. The second value defines the color at that location, so halfway the border the color is #007AFF.

 

I hope that's clear enough, I tend so suck at explaining myself :P

Edited by SinsOfCube
  • 0
  On 21/12/2013 at 16:04, SinsOfCube said:

.left-to-right {
    border-width: 0 0 3px 0;
    -webkit-border-image: 
        -webkit-gradient(linear, 100% 0, 0 0, from(#4cd964), to(#4cd964), color-stop( 50%, #007aff)) 100% 1;
}

From() defines the color at the start, so the border starts with the color #4CD964.

To() defines the color at the end, so the border end with the color #4CD964.

Color-stop() defines a color somewhere inbetween the start and end. You can use more color-stops to add more colors to the gradient, the first value of color-stop defines the location, in this case 50% of the length of the border. The second value defines the color at that location, so halfway the border the color is #007AFF.

 

I hope that's clear enough, I tend so suck at explaining myself :p

 

 

That's great thanks.  But I was thinking more specifically these highlighted numbers:

 

  Quote
linear, 100% 0, 0 0, from(#4cd964), to(#4cd964), color-stop( 50%, #007aff)) 100% 1 
  • 0

http://jsfiddle.net/7493Y/1/

 

Old code:

 

 

  Quote
.left-to-right {
    border-width: 3px 3px 3px 3px;
    -webkit-border-image: 
        -webkit-gradient(linear, 100% 0, 0 0, from(#4cd964), to(#4cd964), color-stop( 50%, #007aff)) 100% 1;

}

 

New Code:

 

 

  Quote
.left-to-right {
    border-width: 3px;
    border-image
        -webkit-gradient(linear, left center, right center, from(#4cd964), to(#4cd964), color-stop( 50%, #007aff)) 3 repeat repeat

}

 

Changes:

  • Changed -webkit-border-image to border-image, for some reason -webkit-border-image also fills the background with the gradient.
  • Changed to reflect what the values there mean, "left center" defines the location of where the gradient starts and "right center" defines the location where the gradient ends. If you change these values you can pick how the gradient flows, from left to right, top to bottom or even left bottom, to right top to get a 45 degrees gradient.
  • Changed the 2 numbers after the gradient definition to adjust the locations the image is cut

 

More information about border-image: http://css-tricks.com/understanding-border-image/

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Seem like they are seeking for a one size fits all. You have power users and "what's a computer" generation growing up on phones, tablets, and Chromebooks.
    • Guessing it was profitable enough inserting prompted apps vs the hate it generated.
    • Also good for Debugging or troubleshooting your game.. i dont get it why nvidia app or amd does not show this data.. if steam can do it..
    • Microsoft reportedly planning to lay off thousands of employees, mostly in sales by Usama Jawad Back in May 2025, Microsoft decided to lay off 3% of its workforce, which amounted to roughly 6,000 employees. It claimed that this decision allowed it to implement better organizational changes in a "dynamic marketplace". Now, a new report claims that the Redmond tech firm is planning to lay off thousands more next month. Citing unnamed sources, Bloomberg reports that as the company continues investing heavily in its AI ventures, it is about to announce layoffs of thousands of workers as early as next month. This reduction in workforce will primarily affect sales teams, but they won't be the only ones affected. That said, the sources did mention that the timing for this announcement may change. This move, if true, won't be entirely surprising. In April 2025, Microsoft announced that it will be relying more on third-party firms to sell its software to small- and medium-sized customers. It's currently unclear how many employees will be impacted by this change, but even if the layoff percentage is in the single digits, it would still be significant as it would be impacting the professional careers of thousands. The May 2025 layoffs primarily impacted engineering and product teams. The other major round of layoffs prior to this was the decision to eliminate 10,000 jobs back in January 2023. Those represented 5% of the total workforce at that time, with numerous teams, including the one leading Mixed Reality (MR) efforts, being heavily impacted. It is interesting to note that if the timing of the announcement for layoffs is accurate, it would be soon after Microsoft closes its fiscal year at the end of June 2025. Although we'll get financial reports for the latest quarter soon after too, one has to wonder what the human cost of profit is, as Microsoft continues to report billions of dollars in revenue every quarter. Source: Bloomberg (paywall)
  • Recent Achievements

    • First Post
      Fuzz_c earned a badge
      First Post
    • First Post
      TIGOSS earned a badge
      First Post
    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      704
    2. 2
      ATLien_0
      285
    3. 3
      Michael Scrip
      213
    4. 4
      +FloatingFatMan
      194
    5. 5
      Steven P.
      131
  • Tell a friend

    Love Neowin? Tell a friend!