Css what is gradient

CSS Gradient

CSS gradients can have a rainbow of options which are often overlooked. Besides the linear-gradient there is the radial and the conic gradient. We explain it here in detail.

CSS Gradient

Color gradient is a free tool for creating css gradients. This tool supports the full css background specification. With color gradient you can easily create simple gradients, as well as far more complex gradient types like patterns and radial gradients. This website also contains some interesting articles about css tricks (involving gradients) you might not yet know about.

Linear gradient

The linear gradient has a start and en and point. Between these two points the colors will blend gradually from one color to another. Writing the gradient in CSS (Cascading Style Sheet) is not difficult. It uses the background image property as a way to make the gradient go from one color to another. To have a gradient from blue left left to green right, you use the following CSS: background-image: linear-gradient(90deg, #A100FFFF 0%, #71C4FFFF 100%); This wil result in a linear gradient from #A100FFFF to #71C4FFFF. Read more about the linear-gradient here. This is linear gradient. Read more

Читайте также:  How to use append in python

Radial gradient

A radial gradient is a transition between one color symmetrically around a circle, giving the appearance of blending colors as they transition. Again we’ll use the background-image CSS property to define the gradient radial gradient. background-image: radial-gradient(100% 100% at 50% 50%, #A100FFFF 0%, #71C4FFFF 100%); This will stretch the circular gradient relative to the size of the element which it is displayed in. The gradient starts with color code #A100FFFF and transitions to the hex color code #71C4FFFF. Read more about the radial gradient here. Read more

Conic gradient

A conic gradient starts with a normal linear gradient and ends with a series of short perpendicular lines which give the appearance of blending colors as they transition. background-image: conic-gradient(from 90deg at 50% 50%, #A100FFFF 0%, #71C4FFFF 100%); This will show a clock-like gradient, with a sharp distinctive line at one end and a color blend to the other. Read more

Gradient generator

Checkout our awesome gradient generator. It’s easy and to use and has many complex css gradient features.

Источник

Css what is gradient

A CSS gradient has no intrinsic dimensions; i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element to which it applies.

Syntax

The data type is defined with one of the function types listed below.

Linear gradient

Linear gradients transition colors progressively along an imaginary line. They are generated with the linear-gradient() function.

Radial gradient

Radial gradients transition colors progressively from a center point (origin). They are generated with the radial-gradient() function.

Repeating gradient

Repeating gradients duplicate a gradient as much as necessary to fill a given area. They are generated with the repeating-linear-gradient() and repeating-radial-gradient() functions.

Conic gradient

Conic gradients transition colors progressively around a circle. They are generated with the conic-gradient() function.

Interpolation

As with any interpolation involving colors, gradients are calculated in the alpha-premultiplied color space. This prevents unexpected shades of gray from appearing when both the color and the opacity are changing. (Be aware that older browsers may not use this behavior when using the transparent keyword.)

Formal syntax

=
|
|
|

=
linear-gradient( [ | to ]? , )

=
radial-gradient( [ || ]? [ at ]? , )

=
[ left | right ] ||
[ top | bottom ]

=
, [ ? , ]#

=
|
|

=
[ left | center | right ] || [ top | center | bottom ] |
[ left | center | right | ] [ top | center | bottom | ]? |
[ [ left | right ] ] && [ [ top | bottom ] ]

=
&&
?

=

=
closest-corner |
closest-side |
farthest-corner |
farthest-side

=
|

Examples

Linear gradient example

div class="linear-gradient">Linear gradientdiv> 
div  width: 240px; height: 80px; > 
.linear-gradient  background: linear-gradient( to right, red, orange, yellow, green, blue, indigo, violet ); > 

Radial gradient example

div class="radial-gradient">Radial gradientdiv> 
div  width: 240px; height: 80px; > 
.radial-gradient  background: radial-gradient(red, yellow, rgb(30, 144, 255)); > 

Repeating gradient examples

Simple repeating linear and radial gradient examples.

div class="linear-repeat">Repeating linear gradientdiv> br /> div class="radial-repeat">Repeating radial gradientdiv> 
div  width: 240px; height: 80px; > 
.linear-repeat  background: repeating-linear-gradient( to top left, lightpink, lightpink 5px, white 5px, white 10px ); > .radial-repeat  background: repeating-radial-gradient( powderblue, powderblue 8px, white 8px, white 16px ); > 

Conic gradient example

A simple conic gradient example. Note that this isn’t supported widely across browser as of yet.

div class="conic-gradient">Conic gradientdiv> 
div  width: 200px; height: 200px; > 
.conic-gradient  background: conic-gradient(lightpink, white, powderblue); > 

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Jul 18, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

CSS Gradients

CSS gradients let you display smooth transitions between two or more specified colors.

CSS defines three types of gradients:

  • Linear Gradients (goes down/up/left/right/diagonally)
  • Radial Gradients (defined by their center)
  • Conic Gradients (rotated around a center point)

CSS Linear Gradients

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.

Syntax

Direction — Top to Bottom (this is default)

The following example shows a linear gradient that starts at the top. It starts red, transitioning to yellow:

Example

Direction — Left to Right

The following example shows a linear gradient that starts from the left. It starts red, transitioning to yellow:

Example

Direction — Diagonal

You can make a gradient diagonally by specifying both the horizontal and vertical starting positions.

The following example shows a linear gradient that starts at top left (and goes to bottom right). It starts red, transitioning to yellow:

Example

Using Angles

If you want more control over the direction of the gradient, you can define an angle, instead of the predefined directions (to bottom, to top, to right, to left, to bottom right, etc.). A value of 0deg is equivalent to «to top». A value of 90deg is equivalent to «to right». A value of 180deg is equivalent to «to bottom».

Syntax

The following example shows how to use angles on linear gradients:

Example

Using Multiple Color Stops

The following example shows a linear gradient (from top to bottom) with multiple color stops:

Example

The following example shows how to create a linear gradient (from left to right) with the color of the rainbow and some text:

Example

Using Transparency

CSS gradients also support transparency, which can be used to create fading effects.

To add transparency, we use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).

The following example shows a linear gradient that starts from the left. It starts fully transparent, transitioning to full color red:

Example

Repeating a linear-gradient

The repeating-linear-gradient() function is used to repeat linear gradients:

Example

A repeating linear gradient:

Источник

Оцените статью