簡體   English   中英

具有響應高度的全寬背景

[英]Full width background with responsive height

我正在嘗試使用 Foundation 來構建具有全寬圖像和負責任高度的標題。 有什么方法可以用 CSS 做到這一點,還是我必須使用 javascript? 你可以幫幫我嗎?

索引.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>

應用程序.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%);
}

應用程序.js:

$(document).foundation();

謝謝。

而不是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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM