我不明白如何使这个响应

时间:2017-03-21 15:20:48

标签: html css iframe responsive-design embed

我正在努力让这个视频嵌入响应。

我成功地制作了平板电脑尺寸,现在我正在尝试使用手机,但是如何在用户调整浏览器窗口大小时对其进行响应...例如:

这应该是这样的: enter image description here

这是调整大小后的样子: enter image description here

标题" Overworld Roleplay"自动更改其位置,但视频没有,当我调整窗口大小时,文本"最后更新:"改变其位置,视频改变其大小,不确定原因:/

它适用于更大的分辨率。 enter image description here

我使用bootstrap但我不知道如何解决这个问题:/

这是我的代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
    <meta name="viewport" content="width=device-width, user-scalable=yes">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Homepage | Overworld RP Devs</title>

    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/maintemplate.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/index.html">Overworld Roleplay</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav navbar-right">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="front container">

      <h1 class="text-primary" id="title" >Overworld Roleplay</h1>
      <h4>Development Website</h4>

    </div><!-- /.container -->

    <!-- <div class="videoWrapperOuter">
        <div class="videoWrapperInner">
            <iframe src="//www.youtube.com/embed/C6-TWRn0k4I" 
            frameborder="0" allowfullscreen></iframe>
        </div> -->

    <div class="video container">
        <div class="col-md-8">
            <div class="vid">
                <iframe src="//www.youtube.com/embed/ac7KhViaVqc" frameborder="0" allowfullscreen></iframe>
                <h2 class="text-info" id="last" >Last Update:</h2>
            </div><!--./vid -->
        </div><!--.col -->
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="../../dist/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
    <script src="/js/collapse.js"></script>
    <script src="/js/transition.js"></script>
    <script src="/js/tooltip.js"></script>
    <script src="/js/tab.js"></script>
    <script src="/js/scrollspy.js"></script>
    <script src="/js/popover.js"></script>
    <script src="/js/npm.js"></script>
    <script src="/js/modal.js"></script>
    <script src="/js/dropdown.js"></script>
    <script src="/js/carrousel.js"></script>
    <script src="/js/button.js"></script>
    <script src="/js/alert.js"></script>
    <script src="/js/affix.js"></script>
  </body>
</html>

body {
  padding-top: 50px;
}

.starter-template {
  padding: 40px 15px;
  text-align: center;
}

html, body {
    background-color: black;
    background: url(/images/bg.jpg); 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-repeat: no-repeat;
    /*background-position: center;*/
    height: 100%;
    margin: 0;
}

.front {
    position: absolute;
    margin-left: 54%;
    margin-top: 7%;
    width: 46%;
}

#title {
    font-size: 60px;
    word-wrap: normal;
}

.vid {
    width: 100%;
    margin-top: 16%;
    margin-left: 3%;
}


iframe {
    max-width: 100%;
    height: auto;
    width: 78%;
    height: 240px;
}

.navbar {
    background-color: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.6);
    border-color: rgba(0, 0, 0, 0.4);
}

.nav.navbar-nav.navbar-right li a {
    color: white;
}

.navbar-default .navbar-brand {
    color: white;
}

.navbar-nav>.active>a, .navbar-nav>.active>a:hover, .navbar-nav>.active>a:focus {
  color:black;
}

#last {
    position: absolute;
    left: 5%;
    top: 15%;
}

.video {
    position: absolute;
}

@media only screen and (min-width:321px) and (max-width:768px) {
    iframe {display: none;}
    #last {display: none; }
    .front {margin-left: 28%; text-wrap: nowrap; text-align: center;}
}

@media only screen and (min-width:768px) and (max-width:1024px) {
    iframe {width: 500px; height: 300px; margin-top: 6%;}
}

正如你所看到的,我底部有两个@media适用于我的平板电脑,1024x768和我的手机较小。

我已完成这些修改:

.vid {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.vid iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

但现在我不确定如何正确调整大小: http://imgur.com/a/FmTjP

1 个答案:

答案 0 :(得分:1)

将此添加到CSS中,它应该在缩小窗口时使视频响应。

.vid {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.vid iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}