HTML5 视频定位到顶部

发布于 2025-01-17 14:28:00 字数 338 浏览 1 评论 0原文

有谁知道如何将视频内容定位到顶部,例如带有背景图像的“位置:顶部”?
我有一个 1920x1080px 的视频,但 div 当前使用 1920x550px。我尝试搜索万维网,但没有成功。

      <video playsinline autoplay muted loop>
          <source src="vid/vid_3.mp4" type="video/mp4">
          Your browser does not support the video tag.
      </video>

亲切地,
路易斯

Does anyone know how to position the video content to the top, like "position: top" with background images?
I have a video that is 1920x1080px, but the div is currently using 1920x550px. I have tried to search the World Wide Web without any luck.

      <video playsinline autoplay muted loop>
          <source src="vid/vid_3.mp4" type="video/mp4">
          Your browser does not support the video tag.
      </video>

Kindly,

Louis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感情洁癖 2025-01-24 14:28:00

感谢您的回复。不幸的是它不起作用,但我设法通过设置高度来修复它:

<video playsinline autoplay muted loop style="height: 1080px;">

Thanks for the reply. Unfortunately it didn't work, but I've managed to fix it by setting the height:

<video playsinline autoplay muted loop style="height: 1080px;">
-黛色若梦 2025-01-24 14:28:00

我的示例将视频图片位置移动到页面顶部。

视频图片位于顶部并不明显,因为导航栏会遮挡它的视图。因此,在 navbar (是

style="top:40px"

设置示例:

<nav id="navbar" 
class="navbar navbar-expand-lg top-navbar sticky is-sticky" 
data-toggle="sticky-onscroll" 
style="top:40px"> 

然后找到 class="col-12 video-wrapper" 的 div 并添加到其 "style" ...

top: -60px

尝试如下设置:

<div class="col-12 video-wrapper" 
style="background-image:url('vid/still_vid_3.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
min-height: 550px;
opacity: 0.4; 
top:-60px">

<video playsinline="" autoplay="" muted="" loop="" controls="">
<source src="vid/vid_3.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

</div>

My example moves the video picture position to the top of page.

It won't be obvious that the video picture is at top since the navbar will block the view of it. So in navbar (is <nav id="navbar" ... > setup code), to move it down for testing, add this to the tag setup:

style="top:40px"

example setup:

<nav id="navbar" 
class="navbar navbar-expand-lg top-navbar sticky is-sticky" 
data-toggle="sticky-onscroll" 
style="top:40px"> 

Then find the div with class="col-12 video-wrapper" and add to its "style" ...

top: -60px

try a setup like this:

<div class="col-12 video-wrapper" 
style="background-image:url('vid/still_vid_3.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
min-height: 550px;
opacity: 0.4; 
top:-60px">

<video playsinline="" autoplay="" muted="" loop="" controls="">
<source src="vid/vid_3.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

</div>
夏九 2025-01-24 14:28:00

我遇到了同样的问题,发现将视频 CSS 高度设置为“自动”对我有用。

以下是编辑 HTML 代码第一行以包含内联 CSS 的示例:

<video playsinline autoplay muted loop style="height: auto;">

I encountered the same issue and found that setting the video CSS height to "auto" worked for me.

Here is an example of editing the first line of your HTML code to include inline CSS:

<video playsinline autoplay muted loop style="height: auto;">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文