Search code examples
htmlcssfootersticky-footer

Sticky Footer floating in page when resizing (reasked)


This question was posted a few years ago By Sally but she solved it herself and her solution is not working for me.

I have gone through practically all of the relevant sticky footer pages on this site and a bunch from other places but I cannot find anything answering this question. I am sure it has to do with my layout but I have tried every way I have researched and can think of and this is the closest I could get to a sticky footer I am happy with.

Here is the HTML I am working with.

<body>
    <div id="container">
        <header class="main-header">
            <a href="index.html"> <img src="logo3.png" alt="logo" /> </a>
            <ul class="main-nav">
                <li><a id="home" href="index.html">Home</a>
                </li>
            </ul>
            <ul class="second-nav">
                <li><a id="about" href="About.html">About Us</a>
                </li>
                <li><a id="portfolio" href="Portfolio.html">Portfolio</a>
                </li>
                <li><a href="SportsComplex.html">Sports Complex</a>
                </li>
                <li><a href="Contact.html">Contact Us</a>
                </li>
            </ul>
        </header>

        <body class="body">
            <div class="frameT">
                <div class="frameTC">
                    <div class="thumb" id="thumbs">
                        <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">_______</span>
                        </a>
                        <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">________</span>
                        </a>
                        <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">________</span>
                        </a>
                        <span class="stretch"></span>
                    </div>
                </div>
            </div>
        </body>

        <footer class="footer">
            <div class="quote">
                <h6>""</h6>
                <p> - </p>
            </div>
        </footer>
    </div>
</body>

and the CSS

/*header*/
.main-header {
    display: inline-block;
    position: relative;
    margin: 1%;
    width: 98%;
    top: 0;
    left: 0;
    min-width: 904px;
    z-index: 10;
    border: 0px solid #2675a9;
    border-top: none;
    border-radius: 0 0 0 0;
    background-color: #606060;
    background-color: rgb(29, 67, 129);
    -webkit-box-shadow:0 1px 5px black;
    -moz-box-shadow:0 1px 5px black;
    box-shadow:0 1px 5px black;
}

.main-header:after {
    content: " ";
    display: table;
    clear: both;
}

.main-header li {
    display: inline;
}

.main-header img {
    position: relative;
    float: left;
    top: 5.5px;
    left: 5.5px;
    width: 60px;
    height: 60px;
}

.main-nav {
    float: left;
    margin: 12.5px 0 12.5px 5px;
    padding: 0;
}

.main-nav a {
    text-shadow: 0.06em 0.08em #2666b1;
    letter-spacing: 4px;
    color: #ebebeb;
    font-family: StonyIsland;
    display: block;
    font-size: 2.5em;
    padding: 0px 10px;
    text-decoration: none;
    margin: 0px;
    font-weight: 300;
}

.logo {
    height: 50px;
    width: 50px;
    top: 0;
    left: 0;
    padding: 10.5px;
    margin: 0;
}

.second-nav {
    float: right;
    border-radius: 4px;
    margin-bottom: 5px;
    margin-top: 5px;
    margin-left: 0;
    margin-right: 0;
    border: none;
    padding: 9.5px;
}

.second-nav > li {
    float: left;
    border: solid 1px #ebebeb;
    border-bottom: none;
    border-top: none;
    border-right: none;
}

.second-nav li:first-child {
    border-left: none;
}

.second-nav li:second-child {
    border-left: none;
}

.second-nav a {
    color: #ebebeb;
    display: block;
    font-family: Capsuula;
    font-size: 1.13em;
    padding: 10px 30px;
    text-decoration: none;
}

a:hover{
    text-shadow: none;
    color: rgb(237, 12, 12);
}

/*body*/
html {
    position: relative;
    height: 100%;
    overflow-x: hidden;
}

ul {
    list-style-type: none;
}

a {
    text-decoration: none;
    font-size: 1.5em;
}

#wrap {
    min-height: 100%;   
}

#main {
    padding-bottom: 60px;
}

body {
    height: 100%;
    margin: 0 0 60px;
    background-color: rgb(255, 255, 255);
}

/*body location*/

 #thumbs {   
    width: auto;
    margin: 0;
    text-align: center;
    -ms-text-justify: distribute-all-lines;
    text-justify: distribute-all-lines;
}

#thumbs a {
    vertical-align: top;
    display: inline-block;
    *display: inline;
    zoom: 1;
    margin-left: 2%;
    margin-right: 2%;
    margin-bottom: 4em;
    margin-top: 12%;
}

#thumbs img {
    width: 300px;
    height: 300px;
    background-color: grey;
    border-radius: 60px;
    box-shadow: 0 1px 20px black;
}

.caption {
    display: block;
}

/*footer*/

footer {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 60px;
    width: 100%;
    background-color: rgba(255, 255, 255) transparent;
    background-color: rgba(255, 255, 255, 0.5);
}

.footer .quote {
    float: right;
    color: rgb(56, 56, 56);
}

.footer h6 {
    font-size: 15px;
    font-family: Capsuula;
    margin: 0;
    padding: 7px;
}

.footer p {
    font-size: 21px;
    font-family: Capsuula;
    float: right;
    margin: 0;
    padding;
    5px;
    padding-right: 12px;
}

Here is my JSfiddle

In my normal full screen the three 300px x 300px squares fit in a line and everything is well and good but when the window size is reduced (like the one in my fiddle) the squares turn into two lines and are pushed off the screen. The footer stays in place at the bottom of the screen until you scroll then it just stays put and does not follow the bottom of the page.

I would like the footer to either get pushed to the bottom of the screen when the squares get forced into two lines.

-or-

Stay at the bottom of the screen and scroll with the user.

Any help would be very much appreciate!


Solution

  • I removed the excess body and turned it into a div. I ended the container before the footer and added a push div, equal in height to the footer. Seems to work now. Check out the fiddle

    /*header*/
     .main-header {
        display: inline-block;
        position: relative;
        margin: 1%;
        width: 98%;
        top: 0;
        left: 0;
        min-width: 904px;
        z-index: 10;
        border: 0px solid #2675a9;
        border-top: none;
        border-radius: 0 0 0 0;
        background-color: #606060;
        background-color: rgb(29, 67, 129);
        -webkit-box-shadow:0 1px 5px black;
        -moz-box-shadow:0 1px 5px black;
        box-shadow:0 1px 5px black;
    }
    .main-header:after {
        content:" ";
        display: table;
        clear: both;
    }
    .main-header li {
        display: inline;
    }
    .main-header img {
        position: relative;
        float: left;
        top: 5.5px;
        left: 5.5px;
        width: 60px;
        height: 60px;
    }
    .main-nav {
        float: left;
        margin: 12.5px 0 12.5px 5px;
        padding: 0;
    }
    .main-nav a {
        text-shadow: 0.06em 0.08em #2666b1;
        letter-spacing: 4px;
        color: #ebebeb;
        font-family: StonyIsland;
        display: block;
        font-size: 2.5em;
        padding: 0px 10px;
        text-decoration: none;
        margin: 0px;
        font-weight: 300;
    }
    .logo {
        height: 50px;
        width: 50px;
        top: 0;
        left: 0;
        padding: 10.5px;
        margin: 0;
    }
    .second-nav {
        float: right;
        border-radius: 4px;
        margin-bottom: 5px;
        margin-top: 5px;
        margin-left: 0;
        margin-right: 0;
        border: none;
        padding: 9.5px;
    }
    .second-nav > li {
        float: left;
        border: solid 1px #ebebeb;
        border-bottom: none;
        border-top: none;
        border-right: none;
    }
    .second-nav li:first-child {
        border-left: none;
    }
    .second-nav li:second-child {
        border-left: none;
    }
    .second-nav a {
        color: #ebebeb;
        display: block;
        font-family: Capsuula;
        font-size: 1.13em;
        padding: 10px 30px;
        text-decoration: none;
    }
    a:hover {
        text-shadow: none;
        color: rgb(237, 12, 12);
    }
    /*body*/
     html {
        position: relative;
        height: 100%;
        overflow-x: hidden;
    }
    ul {
        list-style-type: none;
    }
    a {
        text-decoration: none;
        font-size: 1.5em;
    }
    #wrap {
        min-height: 100%;
    }
    #main {
        padding-bottom: 60px;
    }
    body {
        height: 100%;
        margin: 0 0 60px;
        background-color: rgb(255, 255, 255);
    }
    /*body location*/
     #thumbs {
        width: auto;
        margin: 0;
        text-align: center;
        -ms-text-justify: distribute-all-lines;
        text-justify: distribute-all-lines;
    }
    #thumbs a {
        vertical-align: top;
        display: inline-block;
        *display: inline;
        zoom: 1;
        margin-left: 2%;
        margin-right: 2%;
        margin-bottom: 4em;
        margin-top: 12%;
    }
    #thumbs img {
        width: 300px;
        height: 300px;
        background-color: grey;
        border-radius: 60px;
        box-shadow: 0 1px 20px black;
    }
    .caption {
        display: block;
    }
    /*footer*/
    .push{height:60px;}
     footer {
        position: relative;
        left: 0;
        bottom: 0;
        height: 60px;
        width: 100%;
        background-color: rgba(255, 255, 255) transparent;
        background-color: rgba(255, 255, 255, 0.5);
    }
    footer .quote {
        float: right;
        color: rgb(56, 56, 56);
    }
    footer h6 {
        font-size: 15px;
        font-family: Capsuula;
        margin: 0;
        padding: 7px;
    }
    footer p {
        font-size: 21px;
        font-family: Capsuula;
        float: right;
        margin: 0;
        padding;
        5px;
        padding-right: 12px;
    }
    <body>
        <div id="container">
            <header class="main-header"> <a href="index.html"> <img src="logo3.png" alt="logo" /> </a>
    
                <ul class="main-nav">
                    <li><a id="home" href="index.html">Home</a>
    
                    </li>
                </ul>
                <ul class="second-nav">
                    <li><a id="about" href="About.html">About Us</a>
    
                    </li>
                    <li><a id="portfolio" href="Portfolio.html">Portfolio</a>
    
                    </li>
                    <li><a href="SportsComplex.html">Sports Complex</a>
    
                    </li>
                    <li><a href="Contact.html">Contact Us</a>
    
                    </li>
                </ul>
            </header>
            <div class="body">
                <div class="frameT">
                    <div class="frameTC">
                        <div class="thumb" id="thumbs"> <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                                <span class="caption">_______</span>
                            </a>
     <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                                <span class="caption">________</span>
                            </a>
     <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                                <span class="caption">________</span>
                            </a>
     <span class="stretch"></span>
    
                        </div>
                    </div>
                </div>
            </div>
                </div>
        <div class="push"></div>
            <footer class="footer">
                <div class="quote">
                     <h6>"Hello"</h6>
    
                    <p>-</p>
                </div>
            </footer>
    </body>