treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Help Centering Blog

  • Hi All,
    I am brand new to CSS, and need some help with my new blog, that I'm creating using Weebly. I've been doing all of my work on a mac. When I view my page on the mac, it looks perfect; however, when I veiw it on a PC, it is totally off center--the background, header, text and navigation. I've looked at it on three different PCs, and it looks different on each one (all off center). I'm not sure what I'm doing wrong.
    Can anyone help? I'm pasting the CSS code below. I would be forever grateful if someone could help me figure out what's what!
    Thanks in advance :)

    *|* {
    margin:auto;
    padding:auto;
    }
    body {
    background-image:url('background redo 19.jpg');
    background-position: center-center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    margin: 0pt auto;
    padding: auto;
    min height: 100%;
    min width: 1183pix;
    max width: 1183pix;
    }
    p {
    line-height:1.5;
    }
    h1, h2, h3{
    line-height:1.5;
    }
    #wrapper {
    width:100%;
    margin:0pt auto;
    }
    #contents {
    width:80%;
    margin:0pt auto;
    }
    *html #contents {
    width:1183px;
    }
    #header {
    background-image:url('logo 100.png');
    float:center-center;
    width:900px;
    height:289px;
    text-align:center;
    margin:0pt auto;
    }
    #sitename {
    position:relative;
    float:left;
    padding-top:25px;
    font-family:"times new roman",garamond, serif;
    color:#333333;
    font-size:2.5em;
    text-align:center;
    }
    #navigation {
    float:left;
    background: transparent url(nav_background.jpg) no-repeat center top;
    float:center;
    width:960px;
    height:40px;
    margin:0 auto;
    font-family:"lucida sans", arial, sans-serif;
    font-size:1em;
    }
    #navigation ul {
    float:left;
    padding-left:20px;
    padding-top:12px;
    margin-left:0px;
    width:940px;
    height:28px;
    }
    *html #navigation ul {
    margin-left:-12px;
    }
    #navigation li {
    float:left;
    display:inline;
    font-size:1em;
    padding:12px 20px 13px 20px;
    margin-top:-12px;
    height:15px;
    }
    *html #navigation li {
    margin-right:4px;
    }
    #active {
    float:center;
    background: transparent url(activetab_background.jpg) no-repeat center top;
    color:#fff;
    text-align:center;
    }
    #navigation a:link {
    color:#fff;
    text-decoration:none;
    }
    #navigation a:hover {
    color:#fff;
    text-decoration:none;
    }
    #navigation a:visited {
    color:#fff;
    text-decoration:none;
    }
    #active a:link {
    color:#fff;
    text-decoration:none;
    }
    #active a:hover {
    color:#fff;
    text-decoration:none;
    }
    #active a:visited {
    color:#fff;
    text-decoration:none;
    }
    a:link, a:hover, a:visited {
    color:#198bef;
    font-weight:normal;
    text-decoration:underline;
    }
    #main {
    clear:both;
    width:920px;
    min-height:400px;
    height:auto !important;
    height:400px;
    padding:30px 20px 30px 20px;
    }
    img.image-left {
    margin-right:15px;
    float:left;
    }
    img.image-right {
    margin-left:15px;
    float:right;
    }
    #footer {
    float:left;
    width:960px;
    border-top:1px solid #000000;
    margin:0px 0 30px 0;
    }
    #footer-contents {
    float:left;
    color:#000000;
    font-family:"lucida grande", "lucida sans", arial, sans-serif;
    padding:15px 0 0 20px;
    width:940px;
    height:28px;
    }
    *html #footer-contents {
    margin-top:-5px;
    }
    input {
    background-color:#fff;
    border:1px solid #999;
    font-size:12px;
    }
    textarea {
    background-color:#fff;
    border:1px solid #999;
    font-size:12px;
    }
  • Do you have a link to the site?
  • www.janethread.com
    Thanks so much, Abel!
  • @fordinary I don't know what that is. elaborate please? thx!
  • A link to the website is perfect in this case.

    For starters, I would look into these 31 errors.

    To center your background you'll need to change this:

    background-position: center-center;

    to this:

    background-position: center center;

    The dash in the middle is causing the positioning to fail.
  • What's this?
    *|* {
    margin:auto;
    padding:auto;
    }
  • @thedoc thank you so much! I took out the dash, but I can't tell if it worked yet. The website always looks fine on my mac, so I need to look at it on a pc. 31 errors is a lot! Should I try to fix all of them? Will my website work if I don't fix them?
    Thank you for being so helpful!
  • @christopherburton--not really sure what it is :/
    is it wrong? what should be there instead?
  • The website in most cases will work. Fixing the errors will give you a better understanding of how the code should look, what good practices are, etc.
  • * { margin: 0; padding: 0; }
  • @thedoc Got it! I will try fixing them as best I can. Thanks again for your help.
  • @christopherburton I fixed it. thanks for pointing that out!
  • Hey, (first post!)

    Here are some changes I would make to your site.

    I noticed that the content isn't centered to the background and scrolls at a different percentage than your content. change this:

    #wrapper {
    margin: 0 auto;
    width: 100%;
    }

    to
    #wrapper {
    margin: 0 auto;
    width: 900px;
    }


    also, this one is more a matter of preference but...

    in the body area, make this change:

     background-position: center center;

    change it to
     background-position: center top;


    this will lock your background to the top so you don't have that white border on top. which is happening to me on my 24 inch monitor. You might want consider a bigger background or something that repeats.
  • @deanpogni Thanks for the input! I changed the position to center top. But when I changed the margin to 900px, it went off center again--at least on my screen it did. But maybe it is correct at 900px, as there never appears to be an issue when I'm on a mac, only pc.
  • Read again, he didn't say change the margin but change the width to 900px - huge difference. You will also learn that as Mac's do not have IE, only intelligent browsers, your code probably works in them. However as the majority of people are viewing your site with a PC in anything from IE6 to IE9 you will have to test for these too.

    If you have an Intel Mac you have the possibility to run VMWare or Parallels software which will give you a Virtual PC, to which you can download various different browsers and test them as if you were on a PC.
  • Hey virtual,
    I mis-typed--I did in fact change the width, not margin, and that's what caused it to be off center on my comp. I just had my sister send me a screen shot from her PC, and it was off center there too. The background is centered. Now it's the header, body and navigation that are off.
    I think I will try to download one of the programs that you recommended--I don't want to annoy my sis by making her send me screenshots every 10 min :)
  • Is the site that is up now showing a true picture?
  • Yes, I just published after changing the width.
  • I forgot to mention that the software is not free. I guess you are on a budget as you are using Weebly. The site is off center in Firefox on Mac too, I will have a look in PC and let you know what to do,
  • hah..budget--yes!
    OK. thank you.
  • Change content div width to 900px.
  • Why do you have the navigation down the side? There is an area for it under the header across the top.
  • Just changed to 900px and published--looks good on mac!! Does it look OK on your end?
  • Yes I tested it on both.
  • @virtual--you are awesome!! thank you so much!!! you have no idea how grateful I am :) I've been working on this all week. You've made my day!