【问题标题】:fix footer at bottom using jQuery使用 jQuery 在底部修复页脚
【发布时间】:2018-04-04 15:57:14
【问题描述】:

我想将页脚固定在底部间隙。如果内容较少,页脚即将出现并且内容完整问题已解决,并且页脚应固定在底部,而我将放大或缩小。但是当我缩放时,页脚会转到内容部分

    <head runat="server">
        <asp:contentplaceholder id="HeaderContent" runat="server"></asp:contentplaceholder>
    </head> 

    <body class="hidden-sn white-skin backcolor">
    <form id="form1" runat="server">
    <main>
    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"></asp:contentplaceholder>
    </main>
    <!--main layout-->
    <!--footer-->
    <footer id="footer" style="position:relative;bottom: 0;left: 0;width: 100%; height: 50px;text-align: center; color: rgba(255, 255, 255, 0.6); line-height: 50px; overflow: hidden; font-size: 0.9rem; background-color: rgba(62, 69, 81, 0.3)">
        <div class="footer-copyright">
            <div class="container-fluid">
                © copyright 2016 transgraph consulting pvt.ltd, all rights reserved.
            </div>
        </div>
    </footer>
    </body>
    </html>

这是我的母版页。

    position: relative ---> if content is less coming up.
    position: absolute and fixed ----> if content is more getting on content. 


var docHeight = $(window).height();
          var footerHeight = $('#footer').height();
           var footerTop = $('#footer').position().top + footerHeight;
          if (footerTop < docHeight) {
               $('#footer').css('margin-top', 0 + (docHeight - footerTop) + 'px');
            }

我使用 jQuery 来修复它。将我的页脚固定在底部。建议我使用 CSS 或 jQuery 解决这个问题。我想在底部间隙修复我的页脚。如果内容较少,页脚即将出现并且内容完整问题已解决,并且页脚应固定在底部,而我将放大或缩小。但是当我缩放时,页脚会转到内容部分

【问题讨论】:

标签: jquery html css


【解决方案1】:

没有 Jquery 的 CSS 粘滞页脚

CSS:

html {
  height: 100%;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  position: relative;
  margin: 0;
  padding-bottom: 6rem;
  min-height: 100%;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

.demo {
  margin: 0 auto;
  padding-top: 64px;
  max-width: 640px;
  width: 94%;
}

.demo h1 {
  margin-top: 0;
}

/**
 * Footer Styles
 */

.footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background-color: #efefef;
  text-align: center;
}

HTML:

<div class="demo">
  <h1>CSS “Always on the bottom” Footer</h1>

  <p>Text</p>

  <p>text</p>

  <p>text</p>

  <p>text</p>
</div>

<div class="footer">This footer will always be positioned at the bottom of the page, but <strong>not fixed</strong>.</div>

【讨论】:

    【解决方案2】:

    为什么不使用引导程序? 这更容易。 链接:w3school examples, youtube tutorial

    【讨论】:

      【解决方案3】:

      在这里检查此代码,它将帮助您在底部制作固定页脚,并且在您缩小或放大时应该修复

      <div class="content">
      <h1>Some Thing You Want to do</h1>
      </div>
      <footer class="footer">Footer</footer>
      
      html, body {
      height: 100%;
      margin: 0;
      }
      .content {
      padding: 20px;
      min-height: 100%;
      margin: 0 auto -50px;
      }
      .footer,
      .push {
       height: 50px;
      }
      
      * {
      box-sizing: border-box;
      }
      body {
      font: 16px Sans-Serif;
      }
      h1 {
      margin: 0 0 20px 0;
      }
      p {
      margin: 20px 0 0 0;
      }
      footer {
      background: #42A5F5;
      color: white;
      line-height: 50px;
      padding: 0 20px;
      }
      

      在这里你可以找到演示链接是https://jsfiddle.net/kingtaherkings/08tb0fsm/1/

      【讨论】:

        猜你喜欢
        • 2017-06-10
        • 1970-01-01
        • 2019-06-30
        • 2013-02-05
        • 1970-01-01
        • 2016-09-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多