【问题标题】:Remove white space under sticky footer in Bootstrap 4 on iPhone在 iPhone 上的 Bootstrap 4 中删除粘性页脚下的空白
【发布时间】:2018-04-26 21:35:23
【问题描述】:

在小型移动设备中,我的粘性页脚下方出现了这个空白。例如,在“iPhone SE”屏幕尺寸中查看时。

我在引导示例中使用了相同的页脚和 css,但无法使空白消失。

我认为这是因为我的文本很长,然后我使用媒体查询添加了页脚高度,但它看起来不太好。我不知道如何解决它。任何指导将不胜感激。

/* Sticky footer styles
-------------------------------------------------- */
html {
  position: relative;
  min-height: 100%;

}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
  text
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  line-height: 60px; /* Vertically center the text there */
  background-color: #0000ff
}


/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */

.container {
  width: auto;
  max-width: 680px;
  padding: 0 15px;
}


.text-muted {
    color: #fff!important;
}
<!DOCTYPE html>
<!-- saved from url=(0057)https://getbootstrap.com/docs/4.0/examples/sticky-footer/ -->
<html lang="en" class="gr__getbootstrap_com"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="https://getbootstrap.com/favicon.ico">

    <title>Sticky Footer Template for Bootstrap</title>


    <!-- Bootstrap core CSS -->
    <link href="assets/css/bootstrap.css" rel="stylesheet">
	<link href="assets/css/font-awesome.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="assets/css/dashboard.css" rel="stylesheet">
    <link href="assets/css/sticky-footer.css" rel="stylesheet">
</head>

  <body data-gr-c-s-loaded="true">

    <!-- Begin page content -->
    

    <footer class="footer">
      <div class="container">
        <span class="text-muted">This is a test to check this sticky footer. This footer breaks in small screens.</span>
      </div>
    </footer>


<!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery-3.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="assets/js/popper.js"></script>
    <script src="assets/js/bootstrap.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="assets/js/ie10-viewport-bug-workaround.js"></script>
  

</body></html>

【问题讨论】:

    标签: twitter-bootstrap bootstrap-4


    【解决方案1】:

    出现此问题是因为在小屏幕上,页脚分成两行,并且由于您设置了line-height:60px,因此总共会产生120px,这克服了60px 的高度设置。

    您可以使用media queries 来处理它,或者通过设置overflow:hidden;(并不是最好的解决方案),或者将line-height 替换为一些padding。

    这是一个媒体查询示例。 (用你的文字,问题出现在 514px 左右)

    /* Sticky footer styles
    -------------------------------------------------- */
    html {
      position: relative;
      min-height: 100%;
    
    }
    body {
      /* Margin bottom by footer height */
      margin-bottom: 60px;
      text
    }
    .footer {
      position: absolute;
      bottom: 0;
      width: 100%;
      background-color: #0000ff
    }
    
    @media all  and (min-width: 514px){
        .footer {
            /* Set the fixed height of the footer here */
            height: 60px;
            line-height: 60px; /* Vertically center the text there */
        }
    }
    
    @media all  and (max-width: 514px){
        .footer {
            padding: 10px 0;
        }
    }
    
    
    /* Custom page CSS
    -------------------------------------------------- */
    /* Not required for template or sticky footer method. */
    
    .container {
      width: auto;
      max-width: 680px;
      padding: 0 15px;
    }
    
    
    .text-muted {
        color: #fff!important;
    }
    <!DOCTYPE html>
    <!-- saved from url=(0057)https://getbootstrap.com/docs/4.0/examples/sticky-footer/ -->
    <html lang="en" class="gr__getbootstrap_com"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="https://getbootstrap.com/favicon.ico">
    
        <title>Sticky Footer Template for Bootstrap</title>
    
    
        <!-- Bootstrap core CSS -->
        <link href="assets/css/bootstrap.css" rel="stylesheet">
    	<link href="assets/css/font-awesome.min.css" rel="stylesheet">
        <!-- Custom styles for this template -->
        <link href="assets/css/dashboard.css" rel="stylesheet">
        <link href="assets/css/sticky-footer.css" rel="stylesheet">
    </head>
    
      <body data-gr-c-s-loaded="true">
    
        <!-- Begin page content -->
        
    
        <footer class="footer">
          <div class="container">
            <span class="text-muted">This is a test to check this sticky footer. This footer breaks in small screens.</span>
          </div>
        </footer>
    
    
    <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script src="assets/js/jquery-3.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="assets/js/popper.js"></script>
        <script src="assets/js/bootstrap.js"></script>
        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <script src="assets/js/ie10-viewport-bug-workaround.js"></script>
      
    
    </body></html>

    【讨论】:

    • 这几乎解决了它。非常感谢您的帮助。干杯。
    猜你喜欢
    • 2017-04-10
    • 1970-01-01
    • 2018-03-25
    • 2014-10-04
    • 2018-02-05
    • 2021-03-06
    • 2016-03-15
    • 2021-02-23
    相关资源
    最近更新 更多