SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having hard time with Sticky Footer!

    I want id="bottomContent" to stick.

    I'm taking this approach...

    Code:
    html, body{height: 100%;}
    
    #wrapper{
    	min-height: 100%;
    	margin-top: -432px;
    	}
    
    * html #wrapper {/* ie6 and under only*/
        height:100%;
    }
    
    header {
    	height: 100px;
    	margin-bottom: 10px;
    	border-top: 432px solid red;
    }
    
    #bottomContent{
    	position: relative;
    	float: left;
    	height: 432px;
    }
    It still seems to be a few pixels off. I Inspected Element of my bottom content and it says 432? Is there a better way to double check this?

  2. #2
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,456
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    One has to have a vertically oriented monitor to see the footer stick on your web page... pretty tall page

    Anyway, it seems to stick for me in Firefox. In which browser are you seeing the problem?

    Also, you didn't mention whether the footer is a "few pixels" short or tall... whether a few pixels of white space appears below it, or if it continues to trigger a vertical scrollbar. Where are those few pixels rendered?

    I didn't see either in FF, but may have missed something. Perhaps you could "fine tune" the description a bit.

  4. #4
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,791
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    Did you figure this out? I checked in Saf , FF and Chro on Mac ( with my monitor orientation to ~1600px tall ; yup it rotates ) and it seems ok to me ( I do see that you have a s light scroll bar , maybe that's what you meant?)
    That maybe caused by the 1px border on your footer element( or wrapper? ) , remember: padding and borders ADD to an element's dimension.

  5. #5
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,276
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    The height of your footer is 139px but the ul you have inisde it is 140px and thus gives you a scrollbar.

    Reduce the ul by 1px.

    e.g.
    Code:
    footer ul {
        
        float: right;
        margin-top: 59px;
        text-align: right;
    }
    As the height of the ul is dictated by its content then that may vary due to rounding errors in various browsers where line-height is taken into account. An easier option would be to add overflow:hidden to the footer as well.

  6. #6
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay I did that but it stills seems like there are several pixels I'm missing somewhere on the home page...I have a 1200px height monitor so I'm able to drag my browser pretty tall and there scroll bar still isn't going away.

    Playing around with Dev Tools, I found that if I make my #wrapper margin-top: -442px the scroll goes away. But I have no clue where these extra 10px are coming from?

    This seems to be working fine in FF, but not Chrome or Safari...weird.

    This link has no content so it's easier to play with...
    http://www.ogsindustries.com/lemdev/howtovideos.php

  7. #7
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,456
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    After reading Paul's observation, the problem is clear. The contents of #bottomContent are too precisely fitted into their boxes. Any increase in the height of the font in <footer>, for example, will cause the text to overflow the bottom of the footer box; thus, "breaking" the sticky footer.

    That difference in font size could easily occur on different platforms - PC vs Mac vs Linux, etc. - or when a user zooms their text, or as you are seeing... when you change browsers - probably because the default font or zoom settings are different.

    I would like to suggest a different approach to positioning the <ul> in the footer.
    ADD the BLUE, DELETE the RED.

    Code:
    footer {
        position:relative;
    }
    footer ul {
        position:absolute;
        right:0;
        bottom:0;
        float:right;
        margin-top:60px;
        text-align:right;
    }
    Using this method, the user can almost double the size of the font before the text overflows the footer container. And adding overflow:hidden to the footer box will clip the overflowing text but prevent the scrollbar.

    BUT WAIT... THERE's MORE!

    The above change will help, but not cure, your fundamental design problem. The actual sticky footer is the container #bottomContent which contains more text whose scalable size can also "break" the sticky footer.

    Scalable elements, such as text or possibly vertical padding or margins if measured in ems or percents, must have room to resize within the sticky footer container without changing height of that container.

    The following element uses huge vertical margins to position the text within #bottomContent. Any change in the height of the font (larger or smaller) will change the height of #col2. If the height of #col2 changes, the sticky footer "breaks".
    Code:
    #col2 {
        float: left;
        font-family: sans-serif;
        font-size: 10pt;
        margin: 50px 0;    /* incompatible with sticky footer */
        margin:50px 0 0;   /* consider this instead */
        height:282px;      /* 432px - 150px */
        width: 100%;       /* unnecessary */
    }
    Likewise, the text within .lastone will "break" the sticky footer if zoomed larger. Setting {margin-bottom:0} would help.

    Your particular page design is essentially incompatible with the sticky footer that you have implemented.

    Paul created another type of sticky footer that is not dependent on footer height, that you might consider:
    http://www.sitepoint.com/forums/show...=1#post5272639

    At the very least, I would encourage you to design with a larger font size so users will not be encouraged to zoom text larger and try very hard to include some expansion room around the fonts.

  8. #8
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,276
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Bades View Post
    Okay I did that but it stills seems like there are several pixels I'm missing somewhere on the home page...I have a 1200px height monitor so I'm able to drag my browser pretty tall and there scroll bar still isn't going away.

    Playing around with Dev Tools, I found that if I make my #wrapper margin-top: -442px the scroll goes away. But I have no clue where these extra 10px are coming from?

    This seems to be working fine in FF, but not Chrome or Safari...weird.

    This link has no content so it's easier to play with...
    http://www.ogsindustries.com/lemdev/howtovideos.php
    Hi,

    Ron makes some good observations which you should look at but the extra 10 pixels is actually coming for the bottom margin on your header element collapsing onto the wrapper and making it 10px taller than 100%.

    The reason for this is that you haven't contained your floats properly and thus the margin escapes from the header onto its parent.

    If you remove the 10px bottom margin from the header element the gap will disappear. It will also disappear if you contain the floats.

    Code:
    #wrapper:after{
    content:" ";
    display:block;
    clear:both;
    height:0;
    visibility:hidden;
    }
    The gap would also disappear if you used floats correctly and only float elements that need to be floated. For example the bottom content and the mainContent should not be floated as they are 100% wide do not need to be floats. If you set mainContent to clear:both and not floated it would make #wrapper contain all the content nicely and stop the margin-collapse I mentioned above.

    If you have floated columns then contain the floats with a suitable clearing mechanism and avoid the float everything approach as that leaves you a page with all elements removed from the flow and odd margins collapsing through to who knows where.

  9. #9
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using :after is way of clearing?

  10. #10
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by Bades View Post
    Using :after is way of clearing?
    That's the classic method, often referred to as "clearfix". Placing some non-floated "pseudo" content after the container forces it to wrap around the floats, kind of like putting an empty clearing element in the HTML.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  11. #11
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,276
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Bades View Post
    Using :after is way of clearing?
    More info here:

    http://www.yuiblog.com/blog/2010/09/...n-demystified/
    http://nicolasgallagher.com/micro-clearfix-hack/

    and more in the css FAQ under the float section.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •