javascript 调整大小时如何修复页脚重叠内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27064287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:54:11  来源:igfitidea点击:

How to fix footer overlapping content when resizing

javascriptphpjquerytwitter-bootstrap-3

提问by Dan

I have a problem with a template. On a large screen, it's look fine, like this: picture 1

我的模板有问题。在大屏幕上,它看起来不错,像这样: 图片1

But when I resize my browser, the content won't push the footer down. Here is a picture:

但是当我调整浏览器的大小时,内容不会将页脚向下推。这是一张图片:

picture 2

图2

Here is my code, which is too long so forgive me. index.php

这是我的代码,太长了,请见谅。索引.php

<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <!-- simple code -->
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!-- simple code -->
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container-fluid -->
</nav>

<!-- Begin page content -->
<header>
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <img class="img-responsive" src="<?php echo base_url(); ?>assets/img/simple_img.png" alt="" style="height: 200px;">
                <div class="intro-text">
                    <!-- simple intro -->
                </div>
            </div>
        </div>
    </div>
</header>

<footer class="text-center">
    <div class="footer-above">
        <div class="container">
            <div class="row">
                <div class="footer-col col-md-4">
                    <h3>Location</h3>
                    <p>3481 Melrose Place<br>Beverly Hills, CA 90210</p>
                </div>
                <div class="footer-col col-md-4">
                    <h3>Around the Web</h3>
                    <ul class="list-inline">
                        <!-- some social networks -->
                    </ul>
                </div>
                <div class="footer-col col-md-4">
                    <h3>About Freelancer</h3>
                    <p>Freelance is a free to use, open source Bootstrap theme created by <a href="http://startbootstrap.com">Start Bootstrap</a>.</p>
                </div>
            </div>
        </div>
    </div>
    <div class="footer-below">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    Copyright &copy; Author <?php echo date("Y"); ?>
                </div>
            </div>
        </div>
    </div>
</footer>

Here is my Css, which is also too long so forgive me( I deleted some irrelevant code ).

这是我的 Css,它也太长了,请原谅我(我删除了一些不相关的代码)。

            /* Sticky footer styles
        -------------------------------------------------- */
        html {
          position: relative;
          min-height: 100%;
        }
        body {
          /* Margin bottom by footer height */
          margin-bottom: 60px;
        }
        footer {
          position: absolute;
          bottom: 0;
          width: 100%;
          /* Set the fixed height of the footer here */
          height: 340px;
          background-color: #f5f5f5;
        }


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

        body > .container {
          padding: 60px 15px 0;
        }
        .container .text-muted {
          margin: 20px 0;
        }

        footer > .container {
          padding-right: 15px;
          padding-left: 15px;
        }

        code {
          font-size: 80%;
        }

        /*!
         * Start Bootstrap - Freelancer Bootstrap Theme (http://startbootstrap.com)
         * Code licensed under the Apache License v2.0.
         * For details, see http://www.apache.org/licenses/LICENSE-2.0.
         */

        body {
            overflow-x: hidden;
        }

        header {
            text-align: center;
            color: #fff;
            background: #18bc9c;
        }

        header .container {
            padding-top: 100px;
            padding-bottom: 50px;
        }

        @media(min-width:768px) {
            header .container {
                padding-top: 200px;
                padding-bottom: 69px;
            }

            header .intro-text .name {
                font-size: 4.75em;
            }

            header .intro-text .skills {
                font-size: 1.75em;
            }
        }

        @media(min-width:768px) {
            .navbar-fixed-top {
                padding: 25px 0;
                -webkit-transition: padding .3s;
                -moz-transition: padding .3s;
                transition: padding .3s;
            }

            .navbar-fixed-top .navbar-brand {
                font-size: 2em;
                -webkit-transition: all .3s;
                -moz-transition: all .3s;
                transition: all .3s;
            }

            .navbar-fixed-top.navbar-shrink {
                padding: 10px 0;
            }

            .navbar-fixed-top.navbar-shrink .navbar-brand {
                font-size: 1.5em;
            }
        }

        .navbar {
            text-transform: uppercase;
            font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
            font-weight: 700;
        }

        .navbar a:focus {
            outline: 0;
        }

        .navbar .navbar-nav {
            letter-spacing: 1px;
        }

        .navbar .navbar-nav li a:focus {
            outline: 0;
        }

        .navbar-default,
        .navbar-inverse {
            border: 0;
            background-color:#233140;
        }

        footer {
            color: #fff;
        }

        footer h3 {
            margin-bottom: 30px;
        }

        footer .footer-above {
            padding-top: 50px;
            background-color: #2c3e50;
        }

        footer .footer-col {
            margin-bottom: 50px;
        }

        footer .footer-below {
            padding: 25px 0;
            background-color: #233140;
        }

How can I solve this, so the page content will push the footer down...at any size of browser. Any help is appreciated.

我该如何解决这个问题,以便页面内容将页脚向下推......在任何尺寸的浏览器中。任何帮助表示赞赏。

回答by Chris

Removing position:absolute;from the footerin the css appears to work. Perhaps consider having it set to absolute at wider screen sizes using media queries if having position:absoluteis absolutely (pardon the pun) necessary.

position:absolute;footercss 中删除似乎有效。如果position:absolute绝对(请原谅双关语)有必要,也许可以考虑使用媒体查询在更宽的屏幕尺寸下将其设置为绝对值。

I provided a snippet with the absolute positioning removed, as well as the potential addition to a media query, which is commented out, but there to demonstrate.

我提供了一个删除了绝对定位的片段,以及对媒体查询的潜​​在添加,该内容已被注释掉,但用于演示。

/* Sticky footer styles
        -------------------------------------------------- */
            html {
              position: relative;
              min-height: 100%;
            }
            body {
              /* Margin bottom by footer height */
              margin-bottom: 60px;
            }
            footer {
              width: 100%;
              /* Set the fixed height of the footer here */
              height: 340px;
              background-color: #f5f5f5;
            }
            /* Custom page CSS
        -------------------------------------------------- */
            /* Not required for template or sticky footer method. */
            body > .container {
              padding: 60px 15px 0;
            }
            .container .text-muted {
              margin: 20px 0;
            }
            footer > .container {
              padding-right: 15px;
              padding-left: 15px;
            }
            code {
              font-size: 80%;
            }
            /*!
         * Start Bootstrap - Freelancer Bootstrap Theme (http://startbootstrap.com)
         * Code licensed under the Apache License v2.0.
         * For details, see http://www.apache.org/licenses/LICENSE-2.0.
         */
            body {
              overflow-x: hidden;
            }
            header {
              text-align: center;
              color: #fff;
              background: #18bc9c;
            }
            header .container {
              padding-top: 100px;
              padding-bottom: 50px;
            }
            @media(min-width:768px) {
              header .container {
                padding-top: 200px;
                padding-bottom: 69px;
              }
              header .intro-text .name {
                font-size: 4.75em;
              }
              header .intro-text .skills {
                font-size: 1.75em;
              }
              /*
                ****Optional****
                footer{
                position:absolute;
                bottom:0px;
                }*/
            }
            @media(min-width:768px) {
              .navbar-fixed-top {
                padding: 25px 0;
                -webkit-transition: padding .3s;
                -moz-transition: padding .3s;
                transition: padding .3s;
              }
              .navbar-fixed-top .navbar-brand {
                font-size: 2em;
                -webkit-transition: all .3s;
                -moz-transition: all .3s;
                transition: all .3s;
              }
              .navbar-fixed-top.navbar-shrink {
                padding: 10px 0;
              }
              .navbar-fixed-top.navbar-shrink .navbar-brand {
                font-size: 1.5em;
              }
            }
            .navbar {
              text-transform: uppercase;
              font-family: Montserrat, "Helvetica Neue", Helvetica, Arial, sans-serif;
              font-weight: 700;
            }
            .navbar a:focus {
              outline: 0;
            }
            .navbar .navbar-nav {
              letter-spacing: 1px;
            }
            .navbar .navbar-nav li a:focus {
              outline: 0;
            }
            .navbar-default,
            .navbar-inverse {
              border: 0;
              background-color: #233140;
            }
            footer {
              color: #fff;
            }
            footer h3 {
              margin-bottom: 30px;
            }
            footer .footer-above {
              padding-top: 50px;
              background-color: #2c3e50;
            }
            footer .footer-col {
              margin-bottom: 50px;
            }
            footer .footer-below {
              padding: 25px 0;
              background-color: #233140;
            }
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header page-scroll">
      <!-- simple code -->
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <!-- simple code -->
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>

<!-- Begin page content -->
<header>
  <div class="container">
    <div class="row">
      <div class="col-lg-12">
        <img class="img-responsive" src="<?php echo base_url(); ?>assets/img/simple_img.png" alt="" style="height: 200px;">
        <div class="intro-text">
          <!-- simple intro -->
        </div>
      </div>
    </div>
  </div>
</header>

<footer class="text-center">
  <div class="footer-above">
    <div class="container">
      <div class="row">
        <div class="footer-col col-md-4">
          <h3>Location</h3>
          <p>3481 Melrose Place
            <br>Beverly Hills, CA 90210</p>
        </div>
        <div class="footer-col col-md-4">
          <h3>Around the Web</h3>
          <ul class="list-inline">
            <!-- some social networks -->
          </ul>
        </div>
        <div class="footer-col col-md-4">
          <h3>About Freelancer</h3>
          <p>Freelance is a free to use, open source Bootstrap theme created by <a href="http://startbootstrap.com">Start Bootstrap</a>.</p>
        </div>
      </div>
    </div>
  </div>
  <div class="footer-below">
    <div class="container">
      <div class="row">
        <div class="col-lg-12">
          Copyright &copy; Author
          <?php echo date( "Y"); ?>
        </div>
      </div>
    </div>
  </div>
</footer>

回答by cchapman

The way Bootstrap sees how you want to change sizes for different screen sizes are in the column size identifiers. And each number is a fraction of 12.

Bootstrap 看到您希望如何更改不同屏幕大小的大小的方式在列大小标识符中。每个数字都是 12 的分数。

<div class="footer-col col-md-4">

means you want the footer to take 4/12 of the screen on devices medium or higher. To designate that you want it to be different on different sizes, you would put something like

意味着您希望页脚在中等或更高的设备上占据屏幕的 4/12。要指定您希望它在不同尺寸上有所不同,您可以输入类似

<div class="footer-col col-md-4 col-sm-12">

to mean that you want it to take up 4/12 of the screen on medium devices or larger, and 12/12 of the screen on small devices up to medium.

这意味着您希望它在中型设备或更大的设备上占据 4/12 的屏幕,在小型设备上占据 12/12 的屏幕,直到中型设备。

回答by A Magoon

You have inline styling on your header <img>tag.

您的标题<img>标签上有内联样式。

<img class="img-responsive" src="<?php echo base_url(); ?>assets/img/simple_img.png" alt="" style="height: 200px;">

I would recommend trying to use a new class on that <img>tag, then apply a new @mediaquery to adjust height for different screen sizes.

我建议尝试在该<img>标签上使用新类,然后应用新@media查询来调整不同屏幕尺寸的高度。

Also, having the .img-responsive class on that element may also be conflicting with the inline height styling.

此外,在该元素上使用 .img-responsive 类也可能与行内高度样式相冲突。

回答by Rahul

Add the class "position-relative"

添加“位置相对”类

<!-- Footer Starts -->
  <div class="container-fluid">
    <div class="navbar fixed-bottom position-relative">
      <p>You Footer Content<p>
    </div>
  </div>
<!-- Footer ends -->

Works in Bootstrap v4.3

适用于 Bootstrap v4.3