html - 屏蔽视频 SVG 形状

标签 html css svg video mask

我想将视频插入形状 SVG。

形状看起来像这样:Shape 我将它们导出为 .svg

我尝试使用 mask CSS 并使用 CSS 创建形状以使用 overflow: hidden 但没有任何效果。

我需要你的帮助! 谢谢

最佳答案

您可以使用 clip-path - CSS:作为一个加号object-fit

The clip-path CSS property creates a clipping region that sets what part of an element should be shown. Parts that are inside the region are shown, while those outside are hidden.

无需使用 svg 即可将其应用于视频。

video {
    object-fit: cover;
    clip-path: url(resources.svg#c1);
}

这是一个演示

*{
  box-sizing: border-box;
  padding: 0;
  margin: 0
}
figure{
  width: 100vw;
  height: 400px;
  position: relative;
  background-color: red; 
  overflow: hidden
}
video{
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: polygon(100% 0, 88% 63%, 58% 94%, 46% 94%, 13% 63%, 0 0);
}
figcaption{
  position: absolute;
  width: 100%;
  text-align: center;
  bottom: 28vh;
  font-size: 3vw;
  font-weight: 900;
  text-transform: uppercase;
  z-index: 2;
}
 
<figure>
  <video controls controls autoplay preload="metadata" buffered loop>
 

      <source src="https://www.w3schools.com/html/mov_bbb.mp4"
              type="video/mp4">

      Sorry, your browser doesn't support embedded videos.
  </video>
  <figcaption>My Nice video</figcaption>
</figure>

关于html - 屏蔽视频 SVG 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58420652/

相关文章:

php - Div 没有出现在 PHP echo 语句中,但在 echo 语句之外呈现良好

html - 通过 CSS 垂直显示元素

javascript - 如何将多个 svgs 转换为 png,因为它们在 html 上?

javascript - (倒置)立体投影上的 D3 弧未按要求显示

svg - 使用Inkscape命令行将svg转换为png失败

javascript - 根据错误使用 onerror 替换图像

javascript - 如何在 HTML 元素之后放置文本光标?

javascript - 修复 Popup 顺利抬起

jquery - 针对相同的 child ,但只针对某些不同的 parent ——CSS 和 jQuery 选择器样式

javascript - 页面滚动上的事件菜单项