i

Learn HTML and CSS in 10 Days

Changing the Direction of a Gradient Background

The linear-gradient backgrounds, by default, runs from top to bottom of an element. It changes very smoothly between the 1st color and the second color value. This direction can be made to change by utilizing the keywords or a degree value expressed before any shading qualities.

If we want a gradient to run from left to right of an element, we can apply the keyword value – 'to right'. If we need that the gradient runs from top to right bottom of an element, we can use – 'to right bottom.'

div {

  background: #466368;

  background: linear-gradient(to right bottom, #648880, #293f50);

}

Radial Gradient Background

The linear gradient is good for those that are running from one direction to another, frequently the requirement for radial-gradient arises. Radial background gradients function in the same way as the linear gradient and share a significant number of similar qualities.

div {

  background: #466368;

  background: radial-gradient(#648880, #293f50);

}

The radial gradients functions from inside to outside of a web page element. Thus the first color inside the radial-gradient() function will be inside the center and the 2nd color will be outside.

Gradient Background Example

In the Background Image Example, we are going to replace the old background image for a linear gradient background image.

We will be including 2 ‘background’ properties. The 1st one shows a solid color hexadecimal value while the second one contains the linear-gradient() functions.

HTML

CSS

.notice-success {

  background: #67b11c;

  background: linear-gradient(#72c41f, #5c9e19);

  border: 2px solid #467813;

  border-radius: 5px;

  color: #fff;

  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;

  padding: 15px 20px;

}