我正在尝试制作响应式嵌入式YouTube视频,我不明白@media查询是如何工作的,对我来说它们不起作用..
首先,我尝试在平板电脑上缩小它,但它没有效果:/
我使用的代码:
@media only screen and (min-width:321px) and (max-width:768px) {
.video {width: 40% !important; }
.vid {position: absolute; top: 20%;}
}
我希望视频变小以适应标题左侧和“最后更新:”
图片: (那没起效) http://m.imgur.com/3ydAlCv http://m.imgur.com/AdOmoEv
同样在手机上,我想让youtube视频在标题下面,并将标题和视频集中在一起,但那更难......我甚至无法做出这个小东西..
所以我只想在平板电脑上调整视频大小,以便它适合“最后更新:”和标题“Overworld Roleplay”的左侧。
我的HTML
<!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>
</div><!--./vid -->
<h2 class="text-info" id="last" >Last Update:</h2>
</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;
left: 54%;
top: 30%;
width: 46%;
}
#title {
font-size: 60px;
word-wrap: normal;
}
.vid {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px; height: 0; overflow: hidden;
}
.vid iframe,
.vid object,
.vid embed {
position: absolute;
top: 27%;
left: 3%;
width: 77%;
height: 68%;
border: 0;
}
.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;
left: 3%;
}
@media only screen and (min-width:321px) and (max-width:768px) {
.video {width: 40% !important; }
.vid {position: absolute; top: 20%;}
}
答案 0 :(得分:1)
假设您的.video
是<iframe>
,<embed>
等,请尝试
.video {
max-width: 100%;
height: auto;
}
并将其放在容器(div或section)中,其样式如下:
@media (max-width: 767px) {
.video_container {
width: 40%;
}
}
因此,在宽度较小的视口上,例如,小于767px的容器相对于其父容器将获得40%的宽度,而您的视频内部将仅调整。我希望你得到这种方法。你在标题中提出的问题确实有些广泛。正如其他人所指出的,附加代码永远不会伤害:)