Categories: Uncategorized

CSS Linear Gradient Function

Linear Gradient function is introduced in CSS3 which helps to transform from one color to another seamlessly which would have been a herculean task to achieve, with linear-gradient() function you can achieve something like this.

  • Linear Gradient function takes multiple parameters, you can give the rotation of the colors as deg, percent %, or direction, etc.. the syntax looks something like this.
linear-gradient(direction, color1, color2, ...);

The code for the above-shown image is as follows.

<html>

<head>
    <style>
        body {
            display: flex;
            flex-direction: row;
            background: wheat;
            width: 100%;
            height: 100%;
            margin: 0;
        }

        .div1 {
            width: 50%;
            height: 100%;
            background: wheat;
            color: white;
        }

        .div2 {
            width: 50%;
            height: 100%;
            background: linear-gradient(45deg, yellow, red, transparent);
            color: white;
        }
    </style>
</head>

<body>
    <div class="div1">
    </div>
    <div class="div2">
    </div>
</body>

</html>

In the above example div1 class has a plain background where div2 class uses linear-gradient() with which we were able to achieve the transformation.

Here is complete video explaining linear-gradient() function and repeating-linear-gradient() which will see in an another post.

If you i’m using CSS Flexbox to achieve the side by side window view, if you want to see how you can achieve here is the tutorial for it Flexbox Basics .

rajendra

Share
Published by
rajendra

Recent Posts

Largest Unique Number Java Solution

Question : Given an array of integers A, return the largest integer that only occurs once.…

9 months ago

Jump Search Algorithm In Java

Jump search algorithm is a pretty new algorithm to search for an element in a…

1 year ago

Knuth Morris Pratt Pattern Search Algorithm

What is Knuth Morris Pratt or KMP algorithm ? KMP is an algorithm which is…

1 year ago

Binary Search Algorithm In Java

Binary Search is a Logarithmic search which finds the target element in a sorted array…

1 year ago

Leetcode Integer to Roman Java Solution

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X…

2 years ago

Leetcode Container With Most Water Java Solution

Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such…

2 years ago

This website uses cookies.