全宽背景与响应高度

时间:2017-01-31 04:55:02

标签: javascript jquery html css zurb-foundation

我试图使用Foundation构建一个带有全宽图像和负责高度的标题。有一些方法可以用CSS做到这一点,或者我必须使用javascript?你能帮帮我吗?

index.html:

<!doctype html>
<html class="no-js" lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Site</title>
    <link rel="stylesheet" href="css/foundation.css">
    <link rel="stylesheet" href="css/app.css">
  </head>
  <body>
    <header id="page-header">
      <div class="row">
        <div class="background" data-interchange="[image/background.jpg, default],
          [image/small-background.jpg, small],
          [image/medium-background.jpg, medium],
          [image/large-background.jpg, large],
          [image/xlarge-background.jpg, xlarge]">
          <h1 class="text-center">
            <img data-interchange="[image/logo.png, (default)],
              [image/small-logo.png, (small)],
              [image/medium-logo.png, (medium)],
              [image/large-logo.png, (large)],
              [image/xlarge-logo.png, (xlarge)]" alt="Logo" />
            <noscript>
              <img src="image/logo.png" alt="Logo" />
            </noscript>
          </h1>
        </div>
      </div>
    </header>
    <section id="page-content">
      <div id="services" class="row">
        <div class="small-12 columns">
          <h2 class="text-center">Title</h2>
          <p>Text here</h2>
        </div>
      </div>
    </section>

    <script src="js/vendor/jquery.js"></script>
    <script src="js/vendor/what-input.js"></script>
    <script src="js/vendor/foundation.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>

app.css:

html, body {
  height: 100%;
}

header#page-header {
  height: 100%;
}

header#page-header > div.row {
  height: 100%;
}

header#page-header div.background {
  height: 100%;
  width: 100%;
  background-size: 100% auto;
  background-repeat: no-repeat;
}

header#page-header div.background > h1 {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

app.js:

$(document).foundation();

感谢。

2 个答案:

答案 0 :(得分:0)

而不是height: 100%尝试auto

header#page-header div.background {
  height: auto;  // may be this will work for you
  width: 100%;
  background-size: 100% auto;
  background-repeat: no-repeat;
}

答案 1 :(得分:0)