SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Website not centering on different screen sizes

    Hi everyone

    I am trying to make sure my website is centered on different screen resolutions and sizes. I've tried a lot of techniques on the net and nothing seems to be working :/ At the moment I've manually had to centre everything based on what Im seeing on my 15inch macbook pro screen, but when i looked at my site on a Macbook 13inch..the content was shunted to the right somewhat..definitely not centred.

    Can someone please tell me what's wrong with my code?
    What do I need to change or put in to make this work?

    Thanks

    HTML - HTML1.pngHTML2.png

    CSS - CSS.png



    15 inch - 15.png

    13 inch - 13.png

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Hi mike_1491. Welcome to the forums.

    Try to avod using position: absolute for layout, as it causes all sorts of problems. From a look at your code (the real thing is always better) you first need to add position: relative to your wrapper to give the absolute position elements the proper positioning context. That may mean you'll have to reposition the absolute elements. But as I say, there are better ways to position elements.

  3. #3
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply.
    I've placed position:relative to my wrapper, but what else? I've noticed when I make the window smaller manually, the menu squishes up, whereas the rest of the page doesn't.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    We are happy to help further, but we can't debug an image. A live link to your page would be ideal, but if that's not possible, check out the options for posting code here: http://www.sitepoint.com/forums/show...Posting-Basics

    Even if you set up your code at CodePen, we can then quickly fix it for you.

  5. #5
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Live site http://www.salespointuk.com/index.html Thanks a lot.

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    As I say, using position: absolute for all those elements is not a good strategy, so I advise you to start again with this. Start with a width on your wrapper and margin: 0 auto; which will center the layout.

    Then position elements within that with floats etc. to get a much more flexible and reliable layout. It's the only way, I'm afraid.

    If sticking with position: absolute, you'd have to keep your original wdith and centering on the wrapper (I didn't suggest removing it) and alter all the left and right positioning on your elements. For example, you no longer want left: 250px on left most elements, but left: 0, now that you are positioning everything in relation to the wrapper (because of position: relative). Still, this approach is a world of pain and not appropriate for modern web design.

  7. #7
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, Thanks for your assistance and quick responses. I'll no doubt be back here shortly with more questions. Cheers

  8. #8
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Embarrassing question - so I only really have to change the CSS, the HTML is fine, yes?

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,170
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    You should make an attempt to clean it up a bit if you can http://validator.w3.org/check?uri=ht...Inline&group=0

  10. #10
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by mike_1491 View Post
    Embarrassing question - so I only really have to change the CSS, the HTML is fine, yes?
    Essentially yes, although not the link above. But it's really important to organize your HTML in a way that makes it easier to build the layout. For example, all those icons with text form a logical group that should have their own container. Things like that are really important.

    I was in the same situation some time back, and realized I needed to get a book on HTML/CSS to get a clear idea of all this. A really important thing to do.

  11. #11
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again. As I practise more of it, I think I'm beginning to pick it up a bit more. I've revamped my whole CSS now and I've managed to now get what I wanted.

    www.salespointuk.com

    I realise there are probably errors all over the place, as I say, learning

    The only thing that isn't behaving itself is the menu bar - I like it just as it is, except decreasing the browser window makes it all squished.

    Can someone fix this for me?

  12. #12
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    You could give it a width, such as:

    Code:
    nav ul {
    width: 700px;
    }
    You should put the <nav> element inside the wrapper, though, and then reposition it. At the moment it's positioned in relation to the browser window, so will be off screen in smaller windows.

  13. #13
    SitePoint Member
    Join Date
    Jan 2014
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm anything I seem to try and change with the menu, it just stays exactly the same. I thought I put the <nav> element inside the wrapper in my HTML? My wrapper div ends at the end of my body section.

    www.salespointuk.com/index.html

  14. #14
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by mike_1491 View Post
    I thought I put the <nav> element inside the wrapper in my HTML? My wrapper div ends at the end of my body section.
    There are some errors in your HTML, though. As mentioned above, check the HTML validator to find out where those are. But do remove that <center> element out of your code, too. It's way out of date and not needed.

  15. #15
    SitePoint Evangelist silver trophybronze trophy
    Join Date
    Jul 2013
    Posts
    406
    Mentioned
    22 Post(s)
    Tagged
    0 Thread(s)
    What I should do:
    • Give the body a width of say 98% and a {margin: 0 auto}, then the page is centered at all screen sizes, and can take almost full width for small devices.
    • For the large screens you can set a max-width of the body (eventually for small screens a min-width).
    • Remove the <center> and the #wrapper.
    • Let the logo float left.
    • Put the navigation element after that in the html-code, and give it a float: right.
    • If there is not enough space for the logo and the menu at small screens, the menu will drop under the logo automatically.
    • Give a {clear:both} for the #middletext, and let the #middletext be real text in the html (the image can't adapt to the screen size!).
    • The #middletext can have the #middelline as border-bottom: remove the image (=make it flexible adapting to the screen width, and save a http-request for loading the image).
    • Put the 5 items together in a beautiful list, so that items can drop if they don't fit in the screen-width (and stay centered if dropped).
    • Don't forget to add the <meta> for the charset.

    And see what happens when you resize your browser window.

    To get a beginning:


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
  •