Customize the background color of a clipPath in SVG

I'm looking to design a landing page featuring a colored div with a clip-path, intended to showcase a video playing in the background. However, I'm encountering an issue where the background looks grayish without any clear explanation.

Despite trying various methods, I haven't been able to resolve this problem.

Below is the code snippet I have been working on :

 .video_home_container {

    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
  }

  .video_home_background {
    background: green;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 11;
    width: 100vw;
    height: 100vh;
    clip-path: url(#mask);
  }
  
  ... // rest of the CSS code

... // remaining HTML and SVG code

I could really use some advice here as I'm fairly new to working with svg clip paths and struggling to understand the issue.

Answer №1

It seems that the issue you're facing is concentrated in a small portion of the video content.

My suggestion involves utilizing

clipPathUnits="objectBoundingBox"
for the clip path.

objectBoundingBox
By setting objectBoundingBox, all coordinates within the element become relative to the bounding box of the element where the clipping path is applied. The coordinate system's origin starts at the top left corner of the object bounding box, with the width and height being considered as 1 unit value.

To adjust this length to 1 unit value, I'm applying a scaling factor with

transform="scale(0.0004)"
.

To calculate this value (0.0004), it requires determining the bounding box of the elements inside the clipping path and then dividing 1 by the width: 1 / clip.getBBox().width

.video_home_background {
        background: green;
        width: 100vw;
        clip-path: url(#clip);
      }
<svg class="video_home_overlay_logo" width="0" height="0">
             <clipPath id="clip" clipPathUnits="objectBoundingBox"
                       transform="scale(0.0004)"> 
                <path d="M587.505 411.454H487.962V312.839H587.505V213.814H487.962V115.145H587.505V11.1746H352.65V498.674L587.505 480.804V411.454Z" fill="black"/>
                <path d="M767.851 437.958H816.106L818.101 463.206L949.97 453.124L884.39 11.1746H688.473L626.664 477.88L765.282 467.305L767.851 437.958ZM791.924 126.976C798.809 213.814 805.695 286.68 812.581 345.574H765.856C769.545 299.641 778.043 226.684 791.924 126.976Z" fill="black"/>
... (truncated for brevity)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Carousel issue with sliding on Bootstrap when deployed on various web servers

I am experiencing a strange issue with my website. I have it installed on two different servers, and while the Carousel works perfectly fine on the first server, it does not slide properly on the second server. Here are the links to each version of the we ...

Displaying motion of a vehicle with a series of images

Can anyone provide tips on creating an animation that uses multiple images in CSS or jQuery? I was inspired by a Windows skin and would like to create a rotating car animation. Is this possible? Any advice is greatly appreciated. Thank you! ...

Issue with Bootstrap small column vertical alignment not functioning as expected

I am working on a bootstrap layout with two columns. One column contains multiple elements and text, making it quite long, while the other column only has an image. I am trying to center this image vertically within the left column of content. Here is the ...

Ways to trigger a click event on a dynamically added class utilizing $(this);

I am attempting to retrieve the text when clicking on dynamically appended HTML elements. After some research, I came across the following code snippet: $(document).on('click', '.myClass', function (). However, it seems to work only f ...

The feature to hide columns in Vue-tables-2 seems to be malfunctioning

The issue I'm facing is with the hiddenColumns option not working as expected. Even when I set it to hiddenColumns:['name'], the name column remains visible. I've updated to the latest version, but the problem persists. UPDATE I am tr ...

Positioning a div in the center horizontally may result in content with a large explicit width being

I am in search of a solution to horizontally center content on a webpage, regardless of whether or not it has a defined width. After referencing a Stack Overflow question on centering a div block without the width, I found a great method that works well w ...

Tips on saving HTML table information into a .txt document?

Welcome to my Unique HTML Table. <table> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Email Id</th> <th>Phone Number</th> <th>Prefered C ...

The communication between a Firefox XUL extension and a webpage

Currently developing a Firefox XUL extension and in need of incorporating interaction between the web page and the extension. For instance, whenever a link is clicked on the page, I would like to trigger a function within the XUL extension. Is there any k ...

Ways to verify the presence of an element in a list

I found this interesting JS code snippet: ;(function ($) { $('.filter-opts .opt').click(function(){ var selectedName = $(this).html(); $('.append').append('<li>' + selectedName + '</li> ...

Struggling with pagination problems in Bootstrap 4 and looking to integrate QR code functionality into your blade template?

I am currently facing an issue with generating a batch of QR codes using the SimpleQR code generator in Laravel blade template on the fly for printing. The problem arises when a page break occurs, as it breaks the QR code. I attempted to use the break-insi ...

Using the "margin: auto" property to center the text box

I am having trouble centering the search box. I tried adding marginLeft: "auto",marginRight: "auto" to the search class but it's not working. Can you please advise me on how to fix this issue? Below is my code snippet and a link to the sandbox: https ...

Switching the input to LTR changes the overall direction to LTR while maintaining the RTL placeholder

The text input is currently set to be RTL, including both the placeholder and the actual input. The settings for this were done elsewhere. My question is how can I modify it so that only the input changes to LTR, while the placeholder remains RTL. For exa ...

Dynamic content alongside a stationary sidebar that adjusts in width

Attempting to create a switchable sidebar (toggling between short and long form) using bootstrap, multiple examples, and online resources. The width of the sidebar changes when toggled, and I want the content to appear next to it regardless of its length. ...

Include a div with absolute positioning that fits within the visible browser window

My current project involves creating a graphical canvas map with tooltips, but I am facing a challenge. I need to ensure that the tooltips, which are absolute positioned divs, remain within the viewport. Unfortunately, I am having trouble achieving this. ...

Adjust text alignment dynamically as a div changes size with CSS in ASP.NET

For the menu bar on my site, I utilized flex containers and nested div elements. Currently, all text is aligned at the center. However, when the website is viewed on smaller devices and it resizes, I would like the text to be aligned to the left. Is there ...

What steps are involved in creating a table using Bootstrap framework?

Hey there! I need your expertise on how to create a specific layout using bootstrap: codepen.io/anon/pen/bqJdQJ <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div cl ...

Is it possible to use Bootstrap's Accordion or Alert styles with HTML elements <details> and <summary>?

For my projects, I typically utilize Bootstrap for styling and usually do not include any Javascript as it is unnecessary. However, I am now working on a project that requires a feature similar to Bootstrap's Accordion, which does require Javascript t ...

Stop Swiper Slide from moving when clicked on

I am currently utilizing Swiper JS and have encountered an issue. In my Swiper slider, each slide contains a button. Whenever I click on the slide or the button itself, the slide becomes the active one, causing the entire slider to move. Is there a way to ...

Instructions for integrating AJAX into a PHP script

I am looking to incorporate AJAX into my PHP file so that when I delete an item from a list, the data automatically reloads and the list is updated with the new information. I have created a list of all my data along with a delete button. Below is the PH ...

How can I use the draggable and droppable features to add <li> elements to a <ul> list?

I'm encountering a small issue with controlling the placement of my <li> elements when I implement draggable and droppable from JQuery UI. To better explain the problem, I have created a detailed fiddle: JSFiddle Why is it that the .courseBox ...