我有這個腳本嵌入來自YouTube的視頻。視頻播放良好,但是,我無法設置寬度以使視頻響應。如何做呢?爲什麼我的嵌入式視頻無法響應?
<div class="video-container" id="VideoPlayer"></div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('VideoPlayer', {
videoId: 'yusGUGTVAyw', // YouTube Video ID
width: 560, // Player width (in px)
height: 400, // Player height (in px)
playerVars: {
autoplay: 1, // Auto-play the video on load
controls: 1, // Show pause/play buttons in player
showinfo: 0, // Hide the video title
modestbranding: 1, // Hide the Youtube Logo
loop: 5, // Run the video in a loop
fs: 0, // Hide the full screen button
cc_load_policy: 0, // Hide closed captions
iv_load_policy: 3, // Hide the Video Annotations
autohide: 0 // Hide video controls when playing
},
events: {
onReady: function(e) {
e.target.mute();
}
}
});
}
</script>
這個CSS:
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px; height: 0; overflow: hidden;
}
.video-container iframe,
.video-container object,
.video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
但是,視頻不響應。似乎這個CSS不起作用。我做錯了什麼?