首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何去除背景图像与柔性页脚之间的空白?

如何去除背景图像与柔性页脚之间的空白?
EN

Stack Overflow用户
提问于 2019-12-28 08:23:09
回答 2查看 722关注 0票数 0

我相信我的背景img在它和我的柔性箱粘性页脚之间创造了一个空白。我试过很多种方法,但到目前为止它们只是制造了不同的问题.有人能帮忙吗?我创建了一个占位符图像,这是我的原始背景img的大小,为您重新创建问题!谢谢!

JS固定连接

CSS:

代码语言:javascript
复制
.masthead {
  height: 100vh;
  min-height: 100%;
  background:; /* ie 6 cheat */
  background-image: url('http://via.placeholder.com/3024x4032?Placeholder%27');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Sticky Footer Classes */
body
 {
    display: flex;
    flex-direction: column;
}

html, body
 {
height: 100%;
}

#page-content {
    flex: 1 0 auto;
}

#sticky-footer {
  flex-shrink: 0;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-12-28 08:39:24

这个问题可以通过多种方式解决,

方法0:我认为在页脚标记之前有一些不需要的文本内容。如果该文本内容是有意的,则移到方法2,否则执行以下操作

删除下面的代码片段,代码片段在<body class="d-flex flex-column">下面

代码语言:javascript
复制
  <div id="page-content">
    <div class="container text-center">
      <div class="row justify-content-center">
        <div class="col-md-7">
          <h1 class="font-weight-light mt-4 text-white">Sticky Footer using Flexbox</h1>
          <p class="lead text-white-50">Use just two Bootstrap 4 utility classes and three custom CSS rules and you will have a flexbox enabled sticky footer for your website!</p>
        </div>
      </div>
    </div>
<div id="push"></div>
  </div>

方法1:将页脚移动到内容结束的位置。

代码语言:javascript
复制
#sticky-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

方法2:在样式.css文件中将在类.masthead下定义的CSS背景图像描述移动到正文中。

代码语言:javascript
复制
  background:; /* ie 6 cheat */
  background-image: url('http://via.placeholder.com/3024x4032?Placeholder');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;

(在身体中使用,而不是在.masthead中)

票数 0
EN

Stack Overflow用户

发布于 2019-12-28 09:03:10

这个空白空间是你的页面内容。

您需要将此添加到您的标题中:

代码语言:javascript
复制
.masthead {
    position: absolute;
    width: 100%;
    margin-top: 56px; // your navbar height
}

还可以添加以下内容以显示您的页脚:

代码语言:javascript
复制
#sticky-footer {
    z-index: 1;
}

如果要将内容垂直对齐,请将此类添加到页面内容中:

代码语言:javascript
复制
<div id="page-content">
<div class="container text-center h-100">
<div class="row justify-content-center align-items-center h-100">

查看代码片段:

代码语言:javascript
复制
.masthead {
  height: 100vh;
  min-height: 100%;
  background: ;
  /* ie 6 cheat */
  background-image: url('http://via.placeholder.com/3024x4032?Placeholder');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: absolute;
  /* added */
  width: 100%;
  /* added */
}


/* Sticky Footer Classes */

body {
  display: flex;
  flex-direction: column;
}

html,
body {
  height: 100%;
}

#page-content {
  flex: 1 0 auto;
}

#sticky-footer {
  flex-shrink: 0;
  z-index: 1/* added */
}
代码语言:javascript
复制
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light shadow fixed-top">
  <div class="container">
    <a class="navbar-brand" href="#">website</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
     <span class="navbar-toggler-icon"></span>
   </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#home">Home
        <span class="sr-only">(current)</span>
      </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#about">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#blogs">Blogs</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#events">Events</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#music">Music</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

<!--—Full Page Image Header with Vertically Centered Content —-->
<header class="masthead">
  <div class="container h-100">
    <div class="row h-100 align-items-center">
      <div class="col-12 text-center">
        <h1 class="font-weight-light">website</h1>
        <p class="lead">2nd line</p>
      </div>
    </div>
  </div>
</header>

<div id="page-content">
  <div class="container text-center h-100">
    <div class="row justify-content-center align-items-center h-100">
      <div class="col-md-7">
        <h1 class="font-weight-light mt-4 text-white">Sticky Footer using Flexbox</h1>
        <p class="lead text-white-50">Use just two Bootstrap 4 utility classes and three custom CSS rules and you will have a flexbox enabled sticky footer for your website!</p>
      </div>
    </div>
  </div>
  <div id="push"></div>
</div>
<footer id="sticky-footer" class="py-4 bg-dark text-white-50">
  <div class="container text-center">
    <small>Copyright © website</small>
  </div>
</footer>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59509256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档