1

I am trying to implement a STICKY FOOTER (with unknown Height) for my website in HTML5 and CSS3. I have tried so many ways, but there seems to be a problem with the margin of my main part.

Here is what I have:

 body {
   background: #000;
   font-family: Arial;
 }
 main {
   margin: 50px;
 }
<body>
  <header>
  </header>

  <div id="first">
  </div>

  <main id="main">
  </main>

  <footer>
  </footer>
</body>

The HEADER and FOOTER are equal to the body - so, no more code.

Please note: I have used the reset.css to do everything on my own!

Here is what I tried the last hours:

Please do not recommend the FLEXBOX - that does not work on mobile devices and in the IE 10.

Community
  • 1
  • 1
sjantke
  • 605
  • 4
  • 9
  • 35

2 Answers2

1

I just tried one thing for sticky footer , i am adding its html and css3 code.

I am also giving the reference site.

HTML

<div id="wrap">

    <div id="header">

    </div>

    <div id="main">

    </div>

</div>

<div id="footer">

</div>

The body content should be inside the wrap.

css

html, body {height: 100%;}

#wrap {min-height: 100%;}

#main {overflow:auto;
    padding-bottom: 150px;}  /* must be same height as the footer */

#footer {position: relative;
    margin-top: -150px; /* negative value of footer height */
    height: 150px;
    clear:both;} 

/*Opera Fix*/
body:before {
    content:"";
    height:100%;
    float:left;
    width:0;
    margin-top:-32767px;/
}

I referred the following website for the sticky footer

http://www.cssstickyfooter.com
BalajiG
  • 544
  • 2
  • 15
0

I have made an example for you using jQuery http://jsfiddle.net/ed4xe1z9/

HTML

   <div id="wrap">
        <header>
            <p>The header</p>
        </header>
        <div id="main">
            <div class="the-margin">
                <div id="first">
                     <h1>First Content</h1>

                </div>
                 <h2>Main Content</h2>

            </div>
        </div>
    </div>
    <footer>
        <p>Sticky footer</p>
    </footer>

CSS

        * {
            margin: 0;
        }
        html, body {
            height: 100%;
        }
        #wrap {
            min-height: 100%;
        }
        body {
            background: #000;
            font-family: Arial;
            color: #fff;
        }
        #main {    
            overflow:auto;
        }
        .the-margin{
            margin: 50px;
        }
        footer {
            position: relative;
            clear:both;
        }

jQuery on document ready

$('#main').css('padding-bottom', $('footer').height());
$('footer').css('margin-top', -$('footer').height());
Bojan Petkovski
  • 6,835
  • 1
  • 25
  • 34