The first parameter of the linear-gradient function is the direction in which the gradient should be applied. In the fragment in question, this is to right , and therefore the output looks like columns. To change it to look like lines, just change the direction to to bottom , as in the snippet below.
More about linear-gradient and its arguments here .
div { height: 300px; background: linear-gradient(to bottom, #a2ea4c 200px, #07aa91 200px, #07aa91); }
<div></div>
Below is an explanation of the gradient itself for a better understanding:
- Gradient is
linear-gradient , i.e. colors linearly change in straight lines. - The direction
to bottom means that 0% (or 0px ) is at the top of the container, and 100% is at the bottom of the container. #a2ea4c 200px indicates that the gradient will have a color like #a2ea4c to the 200px mark on top.#07aa91 200px indicates that with the 200px sign, the color of the gradient suddenly changes from #a2ea4c to #07aa91 . This makes it a hard-stop gradient, since a gradual color change does not occur.#07aa91 means that the color remains the same from the 200px mark to the end of the gradient.
The gradient indicated in the second fragment is not displayed for the following reasons:
- The gradient has a color like
#a2ea4c only for the first 200px, but the height of the element is p 300px. - The
p tag is by default a block-level container, and when there is no special CSS style, it takes up 100% of the width. - Thus, the
p tag covers the entire gradient area with a different color.
If you replace the p tag with a div (and thereby bring your custom CSS request), the gradient will be visible, because the width becomes only 20%.
html { background: linear-gradient(to bottom, #a2ea4c 200px, #07aa91 200px, #07aa91); } div { height: 300px; width: 20%; margin: 0 auto; background: teal; }
<div>Lorem ipsum sit amet</div>
Harry source share