Saad
Saad

Reputation: 53959

Materialize footer not going to bottom of page

Is there a way to keep the footer at the bottom of the page, even if there isn't a lot of content? I followed the instructions on the Materialize page and have all my HTML between <header>, <main>, and <footer> tags. I haven't applied any of my own CSS to the footer at all.

Any help would be appreciated.

enter image description here

Here is my HTML:

<body>
  <header>
    <nav role="navigation">
      <div class="nav-wrapper container"><a id="logo-container" href="/" class="brand-logo">Some Title <i class="material-icons left hide-on-med-and-down">apps</i></a>
        <ul id="dropdown" class="dropdown-content">
          <li><a href="">Register</a></li>
          <li class="divider"></li>
          <li><a href="">Sign In</a></li>
        </ul>
        <ul class="right hide-on-med-and-down">
          <li id="timer-tab"><a href="">Tab 1</a></li>
          <li id="stats-tab"><a href="">Tab 2</a></li>
          <li id="graphs-tab"><a href="">Tab 3</a></li>
          <li><a href="" data-activates="dropdown" class="dropdown-button">Tab 4<i class="material-icons right">arrow_drop_down</i></a></li>
        </ul>
      </div>
    </nav>
  </header>

  <main>
    <div class="container">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>
  </main>

  <footer class="page-footer">
    <div class="container">
      <div class="row">
        <div class="col l6 s12">
          <h5 class="white-text">Some Title</h5>
          <p class="grey-text text-lighten-4">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        </div>
        <div class="col l2 offset-l2 s6">
          <h6>About</h6>
          <ul>
            <li><a href="" class="grey-text text-lighten-3">Help</a></li>
            <li><a href="" class="grey-text text-lighten-3">Contact</a></li>
            <li><a href="" class="grey-text text-lighten-3">Suggestions</a></li>
          </ul>
        </div>
        <div class="col l2 s6">
          <h6>Developer</h6>
          <ul>
            <li><a href="" class="grey-text text-lighten-3">Source</a></li>
            <li><a href="" class="grey-text text-lighten-3">Contribute</a></li>
            <li><a href="" class="grey-text text-lighten-3">API Docs</a></li>
          </ul>
        </div>
      </div>
    </div>
    <div class="footer-copyright">
      <div class="container">Made by <a href="">Me </a></div>
    </div>
  </footer>

  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="/js/materialize.min.js"></script>
  <script src="/js/bundle.js"></script>
</body>

Upvotes: 15

Views: 23832

Answers (5)

bnmounir
bnmounir

Reputation: 101

Just in case someone is using react with materialize, I had the same problem caused by the root div so instead of assigning the body with display flex change that to

#root {
         display: flex;
         min-height: 100vh;
         flex-direction: column;
       }

The root is the immediate parent.

Upvotes: 3

M&#225;t&#233; Gregor
M&#225;t&#233; Gregor

Reputation: 121

I also use the correct materialize format according to: https://materializecss.com/footer.html

But it in IE browser. It is not working properly, but, if you also add the following style: style="position:fixed;bottom:0;left:0;width:100%;" it will be ok.

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

main {
  flex: 1 0 auto;
}
<!DOCTYPE html>
<html lang="en">
    <head>
    
    </head>
    <body>
        <header>
        </header>

        <main>
        </main>
        
        <footer style="position:fixed;bottom:0;left:0;width:100%;">
        </footer>
    </body>
</html>

Upvotes: 1

Yohannes Kristiawan
Yohannes Kristiawan

Reputation: 251

Just add this style: position:fixed;bottom:0;left:0;width:100%; at the footer element.

For example:

<footer class="page-footer" style="position:fixed;bottom:0;left:0;width:100%;">
    ...
</footer>

Upvotes: 6

Alex
Alex

Reputation: 8695

According to materializecss: the below rules must be added to your css for getting the sticky footer:

 body {
     display: flex;
     min-height: 100vh;
     flex-direction: column;
 }
 main {
     flex: 1 0 auto;
 }

Jsfiddle

Upvotes: 25

thacilima
thacilima

Reputation: 242

Just to add, Alex answer works perfectly since you have this structure:

<body>
<!-- Header content -->
<main>Page Content</main>
<!-- Footer content --> 
</body>

Upvotes: 13

Related Questions