设置YouTube Iframe嵌入的最大尺寸

发布于 2025-01-31 06:53:58 字数 456 浏览 3 评论 0原文

因此,我希望将YouTube视频嵌入到我的网站上。以下代码效果很好,但扩展到响应性地填充宽度的100%,这在移动设备上很棒,但在桌面上太大。关于如何设置最大尺寸的任何想法?谢谢!

<iframe title="YouTube video player" src="https://www.youtube.com/embed/XXXXXXXXX?loop=0&amp;playlist=XXXXXXXXX" height="350" width="560" allowfullscreen="" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" frameborder="0"></iframe>

So I'm looking to embed youtube videos on my site. The following code works great, but expands to fill 100% of width responsively, which is great on mobile, but too large on desktop. Any ideas on how to set a max size? Thanks!

<iframe title="YouTube video player" src="https://www.youtube.com/embed/XXXXXXXXX?loop=0&playlist=XXXXXXXXX" height="350" width="560" allowfullscreen="" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" frameborder="0"></iframe>

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

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

发布评论

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

评论(2

我要还你自由 2025-02-07 06:53:58

在“ iframe” CSS文件中提供样式。

Give style in the 'iframe' css file.

好听的两个字的网名 2025-02-07 06:53:58

您是否尝试过使用媒体查询?此选项使您可以为每种类型的设备(手机,笔记本电脑等)设置不同的样式。


媒体查询[CSS]

要使用媒体查询,您必须在网页中包含此代码:

@media media-query {

   selector{property: value;}

}

有关媒体查询的更多信息,我建议您这些网站:

https://developer.mozilla.org/es/docs/web/css/@media

https://www.w3schools.com/csssref/cssref/csssref/cssscs3_pr_pr_pr_mediaquery.asp


在这种情况

下,您应该设置“ iframe” iframe“ iframe”样式。 “并为这样的PC用户设置媒体查询:

iframe{width: 100%;}

@media only screen {

   iframe{width: 50%;}

}

值“屏幕”选择笔记本电脑和PC用户,因此只有在客户端位于这些类型的设备之一中,才能更改样式。

我希望这会有所帮助!

Have you tried using a media query? This option allows you to set a different style for each type of device (Mobile Phone, Laptop, etc.).


Media Queries [CSS]

To use a media query you have to include this code in your webpage:

@media media-query {

   selector{property: value;}

}

For more information about media queries I recommend you these websites:

https://developer.mozilla.org/es/docs/Web/CSS/@media

https://www.w3schools.com/cssref/css3_pr_mediaquery.asp


Solution

In this case, you should set a default style for "iframe" and set a media query for pc users like this:

iframe{width: 100%;}

@media only screen {

   iframe{width: 50%;}

}

The value "screen" selects laptop and pc users so you can change the styles only if the client is in one of these types of devices.

I hope this helps!

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