Tranparent gradient to shade a div


I’d like to shade a div to show the user he can scroll to see the rest of the content of the div. Apparently, the only solution available is a linear-gradient to gradually set the color for example from white with opacity 1 to white with opacity 0.
But that’s the problem: my div doesn’t have any background-color. The div is in front of a background-image (not attached to the div). I’d like to "mask" the div with a linear shade, so that the div progressively disappears.
Is there a CSS way to do this?


This is the job of mask:

.box {
  border:2px solid;

body {
 background:linear-gradient(to right,pink,lightblue);
<div class="box">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque mollis velit non massa maximus egestas. Nam fermentum tortor feugiat dui imperdiet euismod. Cras non massa in magna dignissim tempus. Proin in molestie diam, a lacinia nunc. Sed non venenatis arcu.</div>

Answered By – Temani Afif

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published