css footer not displaying at the bottom of the page

后端 未结 9 1421
攒了一身酷
攒了一身酷 2021-01-31 21:56

this is my code for my footer, how can i make it display at the bottom of the page rather than right underneath my content above it?

/*footer */
#footer .column          


        
相关标签:
9条回答
  • 2021-01-31 22:27

    if anyone is stuck with this again, this is a modern solution without hacks

    HTML:

    <div class="demo">
      <h1>CSS “Always on the bottom” Footer</h1>
    
      <p>I often find myself designing a website where the footer must rest at the bottom of the page, even if the content above it is too short to push it to the bottom of the viewport naturally.</p>
    
      <p>However, if the content is taller than the user’s viewport, then the footer should disappear from view as it would normally, resting at the bottom of the page (not fixed to the viewport).</p>
    
      <p>If you know the height of the footer, then you should set it explicitly, and set the bottom padding of the footer’s parent element to be the same value (or larger if you want some spacing).</p>
    
      <p>This is to prevent the footer from overlapping the content above it, since it is being removed from the document flow with <code>position: absolute;</code>.</p>
    </div>
    
    <div class="footer">This footer will always be positioned at the bottom of the page, but <strong>not fixed</strong>.</div>
    

    CSS:

    /**
     * Demo Styles
     */
    
    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;
    }
    
    0 讨论(0)
  • 2021-01-31 22:28

    Bootstrap have an example of a footer that sticks to the bottom of the page here: https://getbootstrap.com/examples/sticky-footer/

    Here is the CSS:

    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: 60px;
      background-color: #f5f5f5;
    }
    

    Then in the HTML:

    <footer class="footer">
    
    </footer>
    
    0 讨论(0)
  • 2021-01-31 22:38

    Material Design Bootstrap has a great class: fixed-bottom. It is what I use.

    0 讨论(0)
提交回复
热议问题