Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Gradients.docx58.8 KB Gradients - Solution.docx
59.3 KB
Quick reference
Gradients
We can create linear and radial gradients.
When to use
Any time you want a multicolored gradient effect.
Instructions
To create a basic linear gradient of two colors:
#gradient {
background: black;
background: -webkit-linear-gradient(#cccccc, blue);
background: -o-linear-gradient(#cccccc, blue);
background: -moz-linear-gradient(#cccccc, blue);
background: linear-gradient(#cccccc, blue);
}
To create a linear gradient with three colors:
#gradient {
background: black;
background: -webkit-linear-gradient(#cccccc, blue, yellow);
background: -o-linear-gradient(#cccccc, blue, yellow);
background: -moz-linear-gradient(#cccccc, blue, yellow);
background: linear-gradient(#cccccc, blue, yellow);
}
To create a linear gradient from left to right:
#gradient {
background: black;
background: -webkit-linear-gradient(left, #cccccc, blue);
background: -o-linear-gradient(right, #cccccc, blue);
background: -moz-linear-gradient(right, #cccccc, blue);
background: linear-gradient(right, #cccccc, blue);
}
To create a linear gradient diagonally:
#gradient {
background: black;
background: -webkit-linear-gradient(left top, #cccccc, blue);
background: -o-linear-gradient(bottom right, #cccccc, blue);
background: -moz-linear-gradient(bottom right, #cccccc, blue);
background: linear-gradient(bottom right, #cccccc, blue);
}
To create a radial gradient of three colors:
#gradient {
background: black;
background: -webkit-radial-gradient(#cccccc, blue, yellow);
background: -o-radial-gradient(#cccccc, blue, yellow);
background: -moz-radial-gradient(#cccccc, blue, yellow);
background: radial-gradient(#cccccc, blue, yellow);
}
Hints & tips
- Gradients can be linear or radial
- Gradients can have 2 or more colors
- You can easily change the direction of the gradient
- You have to write the CSS a little differently for each of the web browsers
Lesson notes are only available for subscribers.