Gradient In CSS3: Circular And Elliptical

Today we are going to continue our discussion on CSS3 Gradients. In the previous post we’ve showed you how to create Linear Gradients. This time we will cover their relative, Circular and Elliptical Gradients

 The Gradient Syntax

The gradient in CSS3 is declared using the background-image property. This is for better compatibility when we also need to add background-color in a single rule set, so that they do not collide with one another. Then, to create the radial gradient we simply call it with this radial-gradient() function. There are four values to be included in the function to set the gradient properly.
The first value defines the gradient position. We can use a descriptive keyword such as top, bottom, center and left, or we can also be more specific like, 50% 50% to set the gradient at the center or 0% 0% to set the gradient to start at top left.
The second value defines the shape and the gradient size, there are two arguments to shape the gradients, first the ellipse which is the default, and the second is circle.
And for the gradient size, we can select one of the following six arguments.
Values Description
closest-side
The gradient’s shape meets the side of the box closest to its center (for circles) or meets both the vertical and horizontal sides closest to the center (for ellipses).
closest-corner
The gradient’s shape is sized so it exactly meets the closest corner of the box from its center.
farthest-side
Similar to closest-side, except the shape is sized to meet the side of the box farthest from its center (or vertical and horizontal sides).
farthest-corner
The gradient’s shape is sized so it exactly meets the farthest corner of the box from its center.
contain
A synonym for closest-side.
cover
A synonym for farthest-corner.
Lastly, the third and the fourth define the color combination. So, here is how we write the syntax to create the Elliptical gradients, and this time we will use cover for the gradient size, so it will spread widely, covering the container;
view plaincopy to clipboardprint?
  1. body {  
  2.     background-image: radial-gradient(center center, ellipse cover, #ffeda3#ffc800);  
  3. }  
To create the Circular gradient we can simply do it this way:
view plaincopy to clipboardprint?
  1. body {  
  2.     background-image: radial-gradient(center centercircle cover, #ffeda3#ffc800);  
  3. }  
As the name implies, the gradient shape will be a circle.

Browser Support

Just take note though, all the browsers are still in the process of providing full support for this feature, so they still need the vendor prefix. Thus, the whole complete syntax that will work in all modern browsers – IE10+, Firefox 3.6+, Chrome 4.0+, Safari 4.0+ and Opera 11+ – will look something like this;
view plaincopy to clipboardprint?
  1. body {  
  2.     background-image: radial-gradient(center bottombottom, ellipse cover, #ffeda3#ffc800);  
  3.     background-image: -o-radial-gradient(center bottombottom, ellipse cover, #ffeda3#ffc800);  
  4.     background-image: -ms-radial-gradient(center bottombottom, ellipse cover, #ffeda3#ffc800);  
  5.     background-image: -moz-radial-gradient(center bottombottom, ellipse cover, #ffeda3#ffc800);  
  6.     background-image: -webkit-radial-gradient(center bottombottom, ellipse cover, #ffeda3#ffc800);  

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Leave a Reply

Your email address will not be published.