By using the CSS Gradient user can create smooth transition from one color to another color and which can create grate effects for background without using any images. Using of gradient is easier to scale and user can also change the color scheme, no download time and no bandwidth can be used and some gradient can be made dynamic using javascript. The syntax of the gradient as shown in below image.
The table below demonstrates the properties of gradient as shown.
Property |
Description |
linear-gradient() |
Which is an horizontal offset in which positive value give shadow to the right side and negative value give shadow to the left side. |
radial gradient() |
Which is an vertical offset in which positive value give shadow to the top and negative value give shadow to the bottom. |
repeating-linear-gradient() |
Which is used to set the blur radius. higher value gives more blur edge of the box and negative values not allowed. |
repeating-radial-gradient() |
Is used to sets the spread radius in which value exapands the shadow in all directions and negative value contracts shadow towards the box. |
linear-gradient()
User can create the linear gradient by using linear-gradient() and the argumentof these gradient is shown below.
linear-gradient(direction/angle(optional) , color-stop-1 , color-stop-2 , .....)
In which direction/angle is an optional argument If nothing is specified then the direction is from top to bottom by default. The code below demonstrates the linear gradient as shown.
[html]
<!DOCTYPE>
<html>
<head>
<style>
div{width:500px;
height:200px;
margin:30px;
border:5px solid #000000;
background-image:linear-gradient(#0000FF,#00FFFF);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
linear-gradient () horizontal direction
User can create gradient along the horizontal direction in which user can specify the direction as an argument using a keyword denoting the direction which gradient should head for example left to right. The code below demonstrates the CSS linear-gradient horizontal direction as shown.
[html]
<!DOCTYPE>
<html>
<head>
<style>
div{width:500px;
height:100px;
margin:30px;
border:5px solid #666;
}
.grad1{
background-image:linear-gradient(to right, #800080, #000080);
/*direction from left-to-right*/
}
.grad2{
background-image:linear-gradient(to left, #800080, #000080 );
/*direction from right-to-left*/
}
</style>
</head>
<body>
<div class="grad1"></div>
<div class="grad2"></div>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
linear-gradient along a angle
User can create the linear gradient along any angle by specifying the angle along which the gradient must be created in which CSS angles follows the coordinate system of a compass. The angle is created from the center of the the gradient box if user gave positive values which moves clock wise direction and negative value means anti clock wise direction. In which angles are automatically converted by the browser with in range of 0deg to 360deg. The code below demonstrates the linear gradient along a angle as shown.
[html]
<!DOCTYPE>
<html>
<head>
<style>
div{width:500px;
height:100px;
margin:30px;
border:5px solid #666;
}
.grad1{
background-image:linear-gradient(to bottom left, #800080, #000080);
/*direction from top-right to bottom-left*/
}
.grad2{
background-image:linear-gradient(to top right, #800080, #000080);
/*direction from bottom-left to top-right*/
}
</style>
</head>
<body>
<div class="grad1"></div>
<div class="grad2"></div>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
Repeating-Linear-gradient
User can repeat the linear gradient with stop points after which the gradient repeat it self using CSS repeating-linear-gradient() The code below demonstrates the CSS repeating linear gradient as shown.
[html]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Repeating Linear Gradient</title>
<style>
div {
width: 600px;
height: 250px;
margin: 10px;
background-image: repeating-linear-gradient(235deg, purple, Navy 3%);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.