1

I have a video nested in a parent div. I would like to set its opacity to a linear-gradient transparency effect from left to right, 100% to 0%. The idea is to see the video at 100% opacity on the left side and at 0% on the right side.

CONTEXT: The overall goal is to blend two videos together with a different linear-gradient opacity when hovering different text-item elements.

My current code:

HTML

<div class="media">
  <video class="media__item" autoplay muted>
    <source src="src.mp4" type="video/mp4" />
    Your browser doesn't support the video tag.
  </video>
</div>

CSS

.media {
  width: 320px;
  height: 240px;
}

.media__item {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  opacity: 50%; /* this is wrong */
}
hexangel616
  • 346
  • 2
  • 19

1 Answers1

0

from what I understood from your question is that you want to play the video like normal but just have an overlay of linear-gradient over it so the code below shows the linear gradient facing to the right from black to zero opacity

hope this code helps you with your journey

.media{
    background: linear-gradient(to right, #000000, rgba(19, 19, 19, 0));
    }
    
.media__item {
  width: 100%;
  height: 100%;
  object-fit: cover;

}
<div class="media">
      <video class="media__item" autoplay muted>
        <source src="src.mp4" type="video/mp4" />
        Your browser doesn't support the video tag.
      </video>
    </div>
Arsham
  • 141
  • 1
  • 9