【问题标题】:bootstrap max-height not working引导最大高度不起作用
【发布时间】:2018-06-30 00:45:34
【问题描述】:

大家好,我有一个引导站点,并且我构建了一个相当基本的头文件,如下所示:

<head>
    <style>
        nav a{
            color: white
        }
        nav {background-color: #1c71b9; }
        .navbar-toggle{border: 3px solid white;}
        .icon-bar{background-color: white;}
        .navbar-brand:hover{background-color: white;
        color: #1c71b9;
        }
        body{margin-top: 50px;}
        h1, h2, h3, h4, h5, h6, p{
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
        }
        .row + .row{margin-top: 20px;}
    </style>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link href="https://fonts.googleapis.com/css?family=Raleway:400,700,800" rel="stylesheet">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="vue.js"></script>
</head>

<header>
 <nav class="navbar navbar-fixed-top">
    <div class="container">
     <div class="navbar-header">
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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.php">My Site</a>
        </div><!--end .navbar-header-->
        <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Subscriptions</a></li>
            <li><a href="#">Templates</a></li>
            <li><a href="#">Stock</a></li>
            <li><a href="#" data-toggle="modal" data-target="#loginModal">Login</a></li>
            <li><a href="#">Signup</a></li>
            </ul>
        </div><!--end #navbar-->
     </div><!--end container-->
    </nav>
     <div class="container">
      <div id="loginModal" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
            <!--modal header-->
                <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">X</button>
                <h2 class="modal-title">Login</h2>
                </div>
                <!--modal body-->
                <div class="modal-body">
                <form role="form">
                    <div class="form-group">
                        <label for="username">Username/Email</label>
                        <input type="text" class="form-control" placeholder="Username/Email" id="username" name="username">
                        <a href="#">Forgot Username</a>
                    </div>
                    <div class="form-group">
                        <label for="password">Password</label>
                    <input type="password" class="form-control" placeholder="Password" name="password" id="password">
                        <a href="#">Forgot Password</a>
                    </div>
                    </form>
                </div>
                <!--modal footer-->
                <div class="modal-footer">
                <button class="btn btn-primary btn-block">Login</button>
                </div>
            </div>
            </div>
        </div>
     </div>
    </header>

我将这个头文件包含在我的 index.php 文档中,并试图制作一个视频,其宽度跨越 100% 的浏览器,最大高度为 800 像素,但无论我做什么视频都无法正常工作两侧的空白不跨越所有宽度。这里的任何帮助都会很棒!我基本上希望视频始终居中且响应迅速。类似于 img-responsive 类。这是索引文件的副本

<?php require_once('header.php');?>
<style>
.videoContainer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 800px; 
  overflow: hidden;
  margin-top: 50px;
}
.videoContainer video {
  /* Make video to at least 100% wide and tall */
  min-width: 100%; 
  max-height: 800px; 

  /* Setting width & height to auto prevents the browser from stretching or squishing the video */
  width: auto;
  height: auto;

  /* Center the video */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
</style>
<body>
    <div align="center" class="videoContainer">
    <video src="Balloon.mp4" autoplay="true" loop="true"></video>
    </div>
</body><?php require_once('header.php');?>
<style>
.videoContainer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 800px; 
  overflow: hidden;
  margin-top: 50px;
}
.videoContainer video {
  /* Make video to at least 100% wide and tall */
  min-width: 100%; 
  max-height: 800px; 

  /* Setting width & height to auto prevents the browser from stretching or squishing the video */
  width: auto;
  height: auto;

  /* Center the video */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
</style>
<body>
    <div align="center" class="videoContainer">
    <video src="Balloon.mp4" autoplay="true" loop="true"></video>
    </div>
</body>

【问题讨论】:

  • 所以你的正文在
    标签之后开始?,那不应该在 header 之前在 head 之后开始吗??
  • 你的权利,我修复了它仍然有问题。
  • 你能发一个sn-p或fiddle,这样别人更容易检查你的问题
  • 也许您可以使用“100vw”而不是“100%”(视口宽度),也许我完全错了,但希望对您有所帮助。
  • 试过了,但它不起作用。我工作的地方目前正在阻止 jsfiddle。你们中的一个可以复制代码并在那里尝试吗?

标签: css bootstrap-4


【解决方案1】:

如果您在容器流体中使用引导包装视频。这跨越了视口的整个宽度 (view documentation)。你可以试试这样:

 <div class="container-fluid">
      <video src="Balloon.mp4" autoplay="true" loop="true"></video>
 </div>

然后在你的css中:

 div video {
     height: 800 px;
 }

【讨论】:

    【解决方案2】:

    如果您希望视频覆盖 div 的整个宽度,请不要为视频设置高度,视频将始终保持其纵横比,因此如果您设置高度,宽度也会相应减小。所以最好的方法是为包裹视频的 div 设置高度,让视频扩展 100%

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多