Results 1 to 6 of 6

Thread: CSS Background Problem - Center isn't Center ?

  1. #1
    Join Date
    Dec 2004
    Location
    Windsor, UK.
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy CSS Background Problem - Center isn't Center ?

    I have a strange problem with CSS backgrounds. I have an image thats 750px wide, and am using css to place a 750px wide background image that repeats on the Y right down the page.

    Therefore putting a white box behind a image that sits top center.

    Here's the page: http://gavinpearce.co.uk/sailing/index.htm

    However the background center and text-align center seem to be in two different places, if you look you'll notice that the image is one more pixel to left and the white is one more pixel to the right. so not right in the center, it does the same if the image size is changed to 749 pixels instead of 750px also ??? How can i get them to both align and why are they not?

    Second problem is any idea how to get rid of the white space between the header image and the menu bar below? I want them to run smooth together but I cant for the life of me figure out how - ive minus padding and minus borders and everything !

    The HTML is:

    HTML Code:
    <html>
    <head>
    
    <title>WORK IN PROGRESS</title>
    <link rel="stylesheet" media="all" type="text/css" href="style.css" />
    
    </head>
    <body>
    
    <img src="header.jpg" alt="Welcome to Silverwing Sailing Club" />
    
    <div id="menu1">
    <ul>
    <li><a href="#nogo">Home</a></li>
    <li><a href="#nogo">About Us</a></li>
    <li><a href="#nogo">Club Boats</a></li>
    <li><a href="#nogo">Training</a></li>
    <li><a href="#nogo">Youth</a></li>
    <li><a href="#nogo">Contact</a></li>
    <li><a href="#nogo">Location</a></li>
    </ul>
    </div>
    
    
    </body>
    </html>
    and the CSS is:

    Code:
    body {
    background: #000033 url(bg.gif) repeat-y 50%; 
    font: 80% arial, verdana, helvetica, sans-serif;
    text-align: center;
    min-width: 750px;
    }
    
    
    
    		#container {
    			position: relative;
    			width: 749px;
    			margin: auto;
    			text-align: center;
    		}
    
    
    #header {background: #f00; border:0; margin: 0; padding: 0;}
    
    img { background: #f00; border:0; margin: 0; padding: 0;}
    
    #menu1 {
      width:750px;
      padding:0; 
      margin:0 auto;
      border: 0; 
      background:#08c url(menu_bg.jpg);
      }
    #menu1 li {
      float:left;
      width:85px;
      list-style-type:none;
      border:0px solid #fff; 
      }
    #menu1 a {
      display:block;
      width:85px;
      color:#fff;
      float: left;
      clear: left; 
      text-align:center; 
      padding:5px 0; 
      text-decoration:none; 
      float:left; 
      }
    
    #menu1 li>a { float: none; }
    
    
    #menu1 a:hover {
      color:#fff; 
      background:#08c;
      }
    Anyway many thanks for even reading this far!!

    Will try and take you out sailing at some point!

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ok, I'm a little confused as to what you want to do.

    One, the image and background are aligned...in firefox anyway. What browser are you using? If it looks back in IE, use IE conditional statements to relatively position the image over the background.

    Two, I can't see the navbar because it's completely white, until you hover over the links.

    Three, you'll get the header image flush with the top of the page by setting the body's margin-top: 0px.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    Dec 2004
    Location
    Windsor, UK.
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Meant in Internet Explorer. Doesn't align correctly. Sorry my fault.

  4. #4
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey there,

    I used to have the same issue with some of my headers in IE. I found that making line-height:0px; resolved the issue.

    I don't see a centering issue in either FF or IE, so I can't speak to that.

    Hope that helps.

  5. #5
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Again, if all else fails, use IE conditional statements. They're not meant to be used constantly, but when you don't want to wrestle with IE, they're an option.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  6. #6
    Join Date
    May 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I changed your code a bit and everything lines up in Fox and IE, but I couldn't figure out why the nav bg doesn't show up in Fox. Hope this helps a little...

    <style>
    body {
    background: #000033;
    font: 80&#37; arial, verdana, helvetica, sans-serif;
    text-align: center;
    width: 750px;
    margin:auto;
    color:#000000;
    }
    #container {
    position: relative;
    width: 750px;
    margin: auto;
    margin-top:0px;
    text-align: center;
    background-color:#FFFFFF;
    }


    #header {background: #f00; border:0; margin: 0; padding: 0; height:241px; width:750px;}

    #nav {
    width:750px;
    height:39px;
    }

    #menu1 {
    width:750px;
    margin:0 auto;
    background:#08c;
    background-image: url(http://www.gavinpearce.co.uk/sailing/menu_bg.jpg);
    background-repeat:no-repeat;
    }

    #menu1 li {
    float:left;
    width:85px;
    list-style-type:none;
    }
    #menu1 a {
    display:block;
    width:85px;
    color:#fff;
    float: left;
    text-align:center;
    padding:5px 0;
    text-decoration:none;

    }

    #menu1 a:hover {
    color:#fff;
    background:#08c;
    }

    </style>
    </head>

    <body>
    <div id="container">
    <br />
    <div id="header">
    <img src="http://www.gavinpearce.co.uk/sailing/header.jpg" alt="Welcome to Silverwing Sailing Club" />
    </div><!-- END HEADER -->

    <div id="nav">

    <div id="menu1">
    <ul>
    <li><a href="#nogo">Home</a></li>
    <li><a href="#nogo">About Us</a></li>
    <li><a href="#nogo">Club Boats</a></li>
    <li><a href="#nogo">Training</a></li>
    <li><a href="#nogo">Youth</a></li>
    <li><a href="#nogo">Contact</a></li>
    <li><a href="#nogo">Location</a></li>
    </ul>
    </div><!-- END MENU 1 -->

    </div><!-- END NAV -->

    text
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />

    </div><!-- END CONTAINER -->

    </body>
    </html>

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
  •