html - 如何使用最小页面大小添加页眉、视频和页脚?

标签 html css

我想要一个带有视频的页眉和页脚,在保持宽高比的同时填充中间内容区域。此外,我想要一个最小页面大小。 Here是我到目前为止所拥有的。我目前的问题是,当我达到最小页面大小时,页眉和页脚会在视频上移动。任何帮助将不胜感激。

HTML

<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>

  <body>
    <div class="header">
      <h2>
        Header
      </h2>
    </div>
    <div class="content">
      <video  class="video" controls>
        <source src="http://media.w3.org/2010/05/bunny/movie.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
      </video>
    </div>
    <div class="footer">
      <h2>
        Footer
      </h2>
    </div>
  </body>

</html>

CSS

.body {
    min-width: 640px;
    min-height: 480px;
}
.header {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    margin: 0;
    width:  100%;
    min-width: 640px;
    height: 50px;
    background-color: #dedede;
}

.content{
    position: fixed;
    top: 50px; /*header height*/
    bottom: 70px; /*footer height*/
    left: 0;
    right: 0;
    overflow: hidden;
    text-align: center;
    background-color: lightblue;
    min-width: 640px;
    min-height: 360px; /*480 - header & footer*/
}

.footer {
    position: fixed;
    z-index: 100;
    bottom: 0;
    left: 0;
    margin: 0;
    padding: 0;
    width: 100%;
    min-width: 640px;
    height: 70px;
    background-color: #dedede;
    text-align: center;
}

.video{
    height: 100% !important;
    width: auto   !important;
    max-width: 100%    !important;
}

最佳答案

调整您的页脚,使其贴在页面底部。将其调整为 position:relative 并设置 a 然后创建一个名为 push 的 div 并将其设置为 70px 的高度(与页脚相同) 将 div id ="push"放在内容和页脚之间。

然后,在您的内容上设置 margin-bottom 为 70px。

完成!

更新代码:

.body {
  min-width: 640px;
  min-height: 480px;
}
.header {
  position: relative;
  z-index: 100;
  top: 0;
  left: 0;
  margin: 0;
  width: 100%;
  min-width: 640px;
  height: 50px;
  background-color: #dedede;
}
.content {
  position: relative;
  left: 0;
  right: 0;
  overflow: hidden;
  text-align: center;
  background-color: lightblue;
  margin-bottom: -70px;
  min-width: 640px;
  min-height: 360px;
  /*480 - header & footer*/
}
.push {
  height: 70px;
  clear: both;
}
.footer {
  position: relative;
  z-index: 100;
  bottom: 0;
  left: 0;
  margin: 0;
  padding: 0;
  width: 100%;
  min-width: 640px;
  height: 70px;
  background-color: #dedede;
  text-align: center;
}
.video {
  height: 100% !important;
  width: auto !important;
  max-width: 100% !important;
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="style.css">
  <script src="script.js"></script>
</head>

<body>
  <div class="header">
    <h2>
        Header
      </h2>
  </div>
  <div class="content">
    <video class="video" controls>
      <source src="http://media.w3.org/2010/05/bunny/movie.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
    </video>
  </div>
  <div class="push"></div>
  <div class="footer">
    <h2>
        Footer
      </h2>
  </div>
</body>

</html>

关于html - 如何使用最小页面大小添加页眉、视频和页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31687225/

相关文章:

html - 如何仅在CSS中模糊背景图像

javascript - AngularJS:将指令应用于所有匹配的标签

javascript - 避免根据显示的图像调整幻灯片 div 大小?

JQuery:获取页面刷新时的滚动位置

javascript - 如何从菜单栏的边框开始下拉而不是直接显示在文本下方

javascript - 如何将 HTML 标记的 Jquery 选择器获取到字符串值?

html - 我在 div 之间的空间不适用于 float 和 margin

php - 对 JavaScript 的函数调用不起作用

css - 宽度 :auto for &lt;input&gt; fields

html - 奇怪的图像行为