【问题标题】:My Responsive youtube embed video doesnt fill the full box我的响应式 youtube 嵌入视频没有填满整个框
【发布时间】:2017-11-17 05:34:47
【问题描述】:

在这之后我搜索了很多。到目前为止,我学会了如何使用绝对定位来制作布局。我用 7-8 个盒子做了我的新的第一个布局。其中几个在主盒子里。我想在这里用 youtube 视频填充 1 个框。我认为一切都是响应的,绝对定位的盒子,所有的 youtube 视频也是响应的,但问题是当我把嵌入到我的盒子里时 - 05 没有填满整个盒子,我的意思是它填满了整个宽度,但是有很多空间在高度选项中。我也尝试过更改填充底部,但如果我在谷歌浏览器“f12”中更改分辨率,它仍然很糟糕。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

  <div id="box-01" class="box"><p> header </p></div>
  <div id="box-02" class="box"><p> main </p>
    <div id="box-05" class="box">   
     <figure>
        <iframe width="560" height="315" src="https://www.youtube.com/embed/nscrstWZz3M" frameborder="0" allowfullscreen></iframe>
        </figure>



</div>
    <div id="box-06" class="box"><p> video1 </p></div>
    <div id="box-07" class="box">


    </div>
    <div id="box-08" class="box"><p> video2 </p></div>
  </div>

  <div id="box-09" class="box"><p> footer </p></div>


</body>
</html>

/* css reset */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}




/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
    display: block;
}







* {
    box-sizing: border-box;
}





body {
  background-color: #333;
  font-size: 1rem;
}



#box-01 {
  background-color: hsla(60, 100%, 60%, .85);

}

#box-02 {
  background-color: hsla(84, 84%, 56%, .85);
}



#box-04 {
  background-color: hsla(279, 60%, 44%, .85);
}



figure {
    height: 0;
    padding-bottom: 56.25%;
    position: relative;
}

  figure iframe {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}
@media (max-width: 768px) { 


  figure {
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    position: relative;
}

  figure iframe {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

}

.box {
   position:absolute;
}

p {

    font-family:"news_gothic";
    font-size:1.3vw;
    font-size-adjust:auto;

    width:90%;

    color:white;
}




#box-01 {
  background-color: hsla(60, 100%, 60%, .85);
  left: 0;
  right: 0;
  height: 9.259%;

}



}
body {
   font-family: Merriweather, 'Times New Roman', serif;
  font-size: 1.125rem;
  line-height: 2rem;
  color: #333;

}


#box-02 {
  background-color: hsla(84, 84%, 56%, .85);
  top: 9.300%;
  left: 0;
  width: 70%;
  height: 74.15vh;
}
@media (max-width: 768px) {

    #box-02 {
    float: right;
  background-color: hsla(84, 84%, 56%, .85);
  top: 9.300%;
  left: 0;
  width: 100%;
  height: 56.15vh;
    max-width: 768px;

}

}


#box-05 {
  background-color: hsla(84, 84%, 56%, .85);
  top: 24.300%;
  left: 4.7%;
  width: 32%;
  height: 41.60vh;
}
@media (max-width: 768px) { 

  #box-05 {
  background-color: hsla(84, 84%, 56%, .85);
  top: 24.300%;
  left: 0;
  width: 47%;
  height: 41.12vh;
    max-width: 768px;
     }


}
#box-06 {
  background-color: hsla(50, 50%, 56%, .85);
  top: 11.150%;
  left: 4.7%;
  width: 32%;
  height: 6.11vh;
}
@media (max-width: 768px) { 

  #box-06 {
 background-color: hsla(50, 50%, 56%, .85);
  top: 11.150%;
      left: 0;
  width: 47%;
  height: 6.11vh;
    max-width: 768px;

  }

}
#box-07 {
  background-color: hsla(84, 84%, 56%, .85);
  top: 24.300%;
  left: 49%;
  width: 32%;
  height: 41.60vh;
}
@media (max-width: 768px) { 

  #box-07 {
  background-color: hsla(84, 84%, 56%, .85);
  top: 24.300%;
  left: 52%;
  width: 48%;
  height: 41.12vh;
    max-width: 768px;
    position:absolute;


  }

}
#box-08 {
  background-color: hsla(50, 50%, 56%, .85);
  top: 11.150%;
  left: 49%;
  width: 32%;
  height: 6.11vh;
}
@media (max-width: 768px) { 

  #box-08 {
 background-color: hsla(50, 50%, 56%, .85);
  top: 11.150%;
  left: 52%;
  width: 48%;
  height: 6.11vh;
    max-width: 768px;

  }

}

#box-09 {
  background-color: hsla(50, 50%, 56%, .85);
  right: 0;
  left: 0;
  bottom: 0;
  height: 16.58vh;
}

}

为什么不垂直填充是什么问题?

【问题讨论】:

    标签: html css youtube embed responsive


    【解决方案1】:

    您在#box-05 上有一个固定高度,因此固定高度不会响应,因为它不会随视频的纵横比缩放。删除它并让它符合其中包含响应式 youtube 嵌入的 figure

    /* css reset */
    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    b, u, i, center,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td,
    article, aside, canvas, details, embed,
    figure, figcaption, footer, header, hgroup,
    menu, nav, output, ruby, section, summary,
    time, mark, audio, video {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 100%;
        font: inherit;
        vertical-align: baseline;
    }
    
    
    
    
    /* HTML5 display-role reset for older browsers */
    article, aside, details, figcaption, figure,
    footer, header, hgroup, menu, nav, section {
        display: block;
    }
    
    
    
    
    
    
    
    * {
        box-sizing: border-box;
    }
    
    
    
    
    
    body {
      background-color: #333;
      font-size: 1rem;
    }
    
    
    
    #box-01 {
      background-color: hsla(60, 100%, 60%, .85);
    
    }
    
    #box-02 {
      background-color: hsla(84, 84%, 56%, .85);
    }
    
    
    
    #box-04 {
      background-color: hsla(279, 60%, 44%, .85);
    }
    
    
    
    figure {
        height: 0;
        padding-bottom: 56.25%;
        position: relative;
    }
    
      figure iframe {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
    }
    @media (max-width: 768px) { 
    
    
      figure {
        height: 0;
        padding-bottom: 56.25%; /* 16:9 aspect ratio */
        position: relative;
    }
    
      figure iframe {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
    }
    
    }
    
    .box {
       position:absolute;
    }
    
    p {
    
        font-family:"news_gothic";
        font-size:1.3vw;
        font-size-adjust:auto;
    
        width:90%;
    
        color:white;
    }
    
    
    
    
    #box-01 {
      background-color: hsla(60, 100%, 60%, .85);
      left: 0;
      right: 0;
      height: 9.259%;
    
    }
    
    
    
    }
    body {
       font-family: Merriweather, 'Times New Roman', serif;
      font-size: 1.125rem;
      line-height: 2rem;
      color: #333;
    
    }
    
    
    #box-02 {
      background-color: hsla(84, 84%, 56%, .85);
      top: 9.300%;
      left: 0;
      width: 70%;
      height: 74.15vh;
    }
    @media (max-width: 768px) {
    
        #box-02 {
        float: right;
      background-color: hsla(84, 84%, 56%, .85);
      top: 9.300%;
      left: 0;
      width: 100%;
      height: 56.15vh;
        max-width: 768px;
    
    }
    
    }
    
    
    #box-05 {
      background-color: hsla(84, 84%, 56%, .85);
      top: 24.300%;
      left: 4.7%;
      width: 32%;
    }
    @media (max-width: 768px) { 
    
      #box-05 {
      background-color: hsla(84, 84%, 56%, .85);
      top: 24.300%;
      left: 0;
      width: 47%;
        max-width: 768px;
         }
    
    
    }
    #box-06 {
      background-color: hsla(50, 50%, 56%, .85);
      top: 11.150%;
      left: 4.7%;
      width: 32%;
      height: 6.11vh;
    }
    @media (max-width: 768px) { 
    
      #box-06 {
     background-color: hsla(50, 50%, 56%, .85);
      top: 11.150%;
          left: 0;
      width: 47%;
      height: 6.11vh;
        max-width: 768px;
    
      }
    
    }
    #box-07 {
      background-color: hsla(84, 84%, 56%, .85);
      top: 24.300%;
      left: 49%;
      width: 32%;
      height: 41.60vh;
    }
    @media (max-width: 768px) { 
    
      #box-07 {
      background-color: hsla(84, 84%, 56%, .85);
      top: 24.300%;
      left: 52%;
      width: 48%;
      height: 41.12vh;
        max-width: 768px;
        position:absolute;
    
    
      }
    
    }
    #box-08 {
      background-color: hsla(50, 50%, 56%, .85);
      top: 11.150%;
      left: 49%;
      width: 32%;
      height: 6.11vh;
    }
    @media (max-width: 768px) { 
    
      #box-08 {
     background-color: hsla(50, 50%, 56%, .85);
      top: 11.150%;
      left: 52%;
      width: 48%;
      height: 6.11vh;
        max-width: 768px;
    
      }
    
    }
    
    #box-09 {
      background-color: hsla(50, 50%, 56%, .85);
      right: 0;
      left: 0;
      bottom: 0;
      height: 16.58vh;
    }
    
    }
    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>JS Bin</title>
    </head>
    
    <body>
    
      <div id="box-01" class="box">
        <p> header </p>
      </div>
      <div id="box-02" class="box">
        <p> main </p>
        <div id="box-05" class="box">
          <figure>
            <iframe width="560" height="315" src="https://www.youtube.com/embed/nscrstWZz3M" frameborder="0" allowfullscreen></iframe>
          </figure>
    
    
        </div>
        <div id="box-06" class="box">
          <p> video1 </p>
        </div>
        <div id="box-07" class="box">
    
    
        </div>
        <div id="box-08" class="box">
          <p> video2 </p>
        </div>
      </div>
    
      <div id="box-09" class="box">
        <p> footer </p>
      </div>
    
    
    </body>
    
    </html>

    【讨论】:

    • 这非常有帮助,谢谢 :) 热爱这个社区
    猜你喜欢
    • 1970-01-01
    • 2021-12-19
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 2013-03-07
    • 2015-03-18
    • 1970-01-01
    相关资源
    最近更新 更多