Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate solid colors using CSS linear-gradient (not smooth colors)

Assuming my linear CSS gradient looks like this:

background: linear-gradient(to right, red 0%, green 20%, blue 40%, purple 60%, yellow 80%, black 100%)

It will generate a CSS gradient that looks like this:

enter image description here

How do I make the same gradient but with solid colors without the transitioning between the colors? (using CSS)

Something similar to this:

enter image description here Thanks

like image 937
Evgeny Boxer Avatar asked Jul 14 '17 07:07

Evgeny Boxer


People also ask

What is a linear gradient in CSS?

A linear gradient follows a straight line, with several color placed along that line. The space between these colors will gradually blend from one color to another. When writing the gradient in CSS (Cascading Style Sheet) it uses the background image property as a way to make the gradient go from one color to another.

Which color does the linear gradient start at?

This linear gradient starts at the top. It starts red, transitioning to yellow, then to blue: More "Try it Yourself" examples below. The linear-gradient () function sets a linear gradient as the background image.

How to create a linear gradient in Photoshop?

To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect. Example of Linear Gradient:

How to render smooth transitions among colors?

Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect. Example of Linear Gradient:


1 Answers

Like this

.gradient {
  width: 500px;
  height: 200px;
  background: linear-gradient(to right, 
      red    20%, 
      green  20%, 
      green  40%, 
      blue   40%, 
      blue   60%, 
      purple 60%, 
      purple 80%, 
      yellow 80%,
      yellow 100%
  );
}
<div class="gradient"></div>
like image 119
fen1x Avatar answered Sep 22 '22 13:09

fen1x