英雄视频和图像以及各种设备

发布于 2025-02-13 17:23:57 字数 262 浏览 5 评论 0原文

我实际上花了几个小时试图缩小我的英雄视频以适合WordPress页面的计算机屏幕。设置标准维度似乎仍在扩展。现在,我正在与Mobile的Hero Hoster图片作斗争。是否可以使用CSS来使图像的宽度适合设备的宽度?我真的很努力,希望提供一些帮助!

链接到网站: http://christap4.sg-host.com

I have literally spent hours trying to size my hero video to fit the computer screen for a wordpress page. Setting standard dimensions still seem to have it stretched. Now I am fighting with the hero poster image for mobile. Is there CSS that can be used to make the width of the image fit the width of the device? I am really at my wits end and would love some help!

Link to site: http://christap4.sg-host.com

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

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

发布评论

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

评论(2

我家小可爱 2025-02-20 17:23:57

从您的链接中,这就是我想到的。

body { margin: 0 } /* this is just for the snippet, ignore it */
<video id="wp-custom-header-video" autoplay="" loop="" playsinline="" src="http://christap4.sg-host.com/wp-content/uploads/2022/06/2AE-Hero-Video-20220616.mp4" style="width: 100vw;height: auto;opacity: 1;aspect-ratio: 1.77777778;"></video>

要获得100%的屏幕宽度,您可以使用宽度:100VW(vw = fiewport width)。我还包括accept-Ratio:1.77777778 < / code>(视频宽度 /视频高度),然后将高度设置为自动

From your link this is what I came up with.

body { margin: 0 } /* this is just for the snippet, ignore it */
<video id="wp-custom-header-video" autoplay="" loop="" playsinline="" src="http://christap4.sg-host.com/wp-content/uploads/2022/06/2AE-Hero-Video-20220616.mp4" style="width: 100vw;height: auto;opacity: 1;aspect-ratio: 1.77777778;"></video>

To get 100% of the screen width you can use width: 100vw (vw = viewport width). I've also included ascpect-ratio: 1.77777778 (video width / video height) and then set the height to auto

星光不落少年眉 2025-02-20 17:23:57

看起来这里有几件事。

查看您的输出,看起来您已经过度复杂了解决方案。任何具有100%宽度的绝对位置的任何位置都将与最相对的父母一样宽(默认情况下)。

如果将宽度设置为100%,则可以使用fack-ratio设置高度( https://developer.mozilla.org/en-us/docs/web/css/aspect-ratio )。我不确定您在浏览器支持方面走了多远,但这将涵盖大多数用途。

另外,您可以给它一个固定的高度并使用对象合适的盖,但这会导致一些裁剪。

海报图像将仅继承与视频相同的维度。话虽如此,现在可以自动播放的视频可以自动播放,只要它们是正确的格式,并在其上设置了正确的属性。

Looks like there are a couple of things here.

Looking at your output it looks like you have over-complicated the solution. Anything that is position absolute with 100% width will be as wide as it's most relative parent (by default the body).

If you set the width to 100% you can set the height using aspect-ratio ( https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio ). I'm not sure how far back you are going in browser support but this will cover most uses.

Alternatively you can give it a fixed height and use object-fit cover but this will cause some cropping.

The poster image will just inherit the same dimensions as the video. That being said short videos can now autoplay providing they are the right format, muted and have the right attributes set on them.

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