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

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在“ iframe” CSS文件中提供样式。
Give style in the 'iframe' css file.
您是否尝试过使用媒体查询?此选项使您可以为每种类型的设备(手机,笔记本电脑等)设置不同的样式。
媒体查询[CSS]
要使用媒体查询,您必须在网页中包含此代码:
有关媒体查询的更多信息,我建议您这些网站:
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用户设置媒体查询:
值“屏幕”选择笔记本电脑和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:
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:
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!