如果我理解正确,即使div
您正确调整了 YouTube 视频的大小,也无法让您的 YouTube 视频调整到屏幕宽度。如果是这样,请阅读Chris Coyier 关于调整 YouTube 视频大小的文章。
您可以在 jQuery 中完成所有这些操作(如果您正在使用它),这是 Chris 的代码:
$(function() {
// Find all YouTube videos
var $allVideos = $("iframe[src^='http://www.youtube.com']"),
// The element that is fluid width
$fluidEl = $("body");
// Figure out and save aspect ratio for each video
$allVideos.each(function() {
$(this)
.data('aspectRatio', this.height / this.width)
// and remove the hard coded width/height
.removeAttr('height')
.removeAttr('width');
});
// When the window is resized
// (You'll probably want to debounce this)
$(window).resize(function() {
var newWidth = $fluidEl.width();
// Resize all videos according to their own aspect ratio
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.data('aspectRatio'));
});
// Kick off one resize to fix all videos on page load
}).resize();
});