html - 移动设备上的 Youtube iframe,宽度不佳

标签 html css iframe youtube

我的页面 zaybee.pl 上有关于 youtube iframe 的问题,当你用 youtube 查看帖子中的小窗口时,一切正常 - youtube 宽度更改为窗口宽度:

View on small windows on computer

但在手机(Android、Google Chrome)上,iframe 比网页的其余部分大:

enter image description here

页面上的其余元素具有良好的宽度。 在桌面测试人员上,页面在移动设备上的外观如何,一切看起来都不错。我不知道问题在哪里。

我的代码片段:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>

<div class="ytframe"><iframe width="100%" height="364" style="position:relative;z-index:100;" src="http://www.youtube.com/embed/'.$src['v'].'?wmode=transparent" frameborder="0" allowfullscreen></iframe></div>

.ytframe {width:calc(100% - 77px);height:400px;position:relative;}

最佳答案

您可以使用此 CSS 使 YouTube iframe 在移动设备和 ipad 上响应

.iframeVideo {
	height: 0px;
	padding-top: 25px;
	padding-bottom: 56.2%;
	position: relative;
}
.iframeVideo iframe {
	width: 100%;
	height: 100%;
	position: absolute;
}
<div class="iframeVideo">
<iframe src="https://www.youtube.com/embed/Jiji_1iosv4" frameborder="0" allowfullscreen></iframe>
</div>

关于html - 移动设备上的 Youtube iframe,宽度不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45413689/

相关文章:

javascript - jQuery 定位与 CSS3 "transform: scale"

css - 无法在 div 中垂直居中 Logo 图像

javascript - 使用 Curl php 抓取 iframe 内容

html - CSS 子导航问题

jquery - Bootstrap 4 中 Carousel 整页图像 slider 和多 div slider 的冲突

html css 设计好的做法?

javascript - 不安全的 JavaScript 尝试访问 Google Chrome 中的框架

javascript - 如何从父窗口中的 iframe(Sharepoint 托管应用程序,(应用程序部分)))打开模式对话框弹出窗口

python - 如何选择伪元素并更改状态 from::after a::before?

php - 单击按钮提交数据库中的 div 内容