2015-08-08 103 views
0

我试图在一个HTML页面中嵌入一个带有iframe的YouTube视频。我在怀疑(大小是错误的)。该链接的视频:https://www.youtube.com/watch?v=EqQ6gy-tT9Y?autoplay=1Html视频显示 - 大小不正确?

我的HTML代码:

<section id="test"> 
    <div style="text-align: center;"> 
    <iframe src="https://www.youtube.com/watch?v=EqQ6gy-tT9Y? 
       autoplay=1" width="420" height="315" align="center"> 
     <p>Your browser does not support iframes.</p> 
    </iframe> 
    </div> 
</section> 

回答

1

你应该已经从YouTube复制的嵌入代码:

<iframe width="560" height="315" src="https://www.youtube.com/embed/EqQ6gy-tT9Y?autoplay=1" frameborder="0" allowfullscreen></iframe> 

注意,链接是:

https://www.youtube.com/embed/EqQ6gy-tT9Y

而不是

https://www.youtube.com/watch?v=EqQ6gy-tT9Y

你的代码应该是:

<section id="test"> 
       <div style="text-align: center;"> 
       <iframe src="https://www.youtube.com/embed/EqQ6gy-tT9Y?autoplay=1" width="420" height="315" align="center"> 
        <p>Your browser does not support iframes.</p> 
       </iframe> 

       </div> 
    </section> 

顺便说一句。:您曾在<iframe src="">属性断行,我不知道,如果你只是这样做是为了便于阅读,但其根源问题,保持html元素属性之外的换行符

+0

谢谢!现在很清楚 – Jack