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 :confused: 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 -

CSS -

15 inch -

13 inch -

Hi mike_1491. Welcome to the forums. :slight_smile:

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.

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.

We are happy to help further, but we can’t debug an image. :wink: 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/showthread.php?1041498-Forum-Posting-Basics

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

Live site http://www.salespointuk.com/index.html Thanks a lot.

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.

Ok, Thanks for your assistance and quick responses. I’ll no doubt be back here shortly with more questions. Cheers

Embarrassing question - so I only really have to change the CSS, the HTML is fine, yes?

You should make an attempt to clean it up a bit if you can http://validator.w3.org/check?uri=http%3A%2F%2Fwww.salespointuk.com%2Findex.html&charset=(detect+automatically)&doctype=Inline&group=0

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. :slight_smile:

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 :slight_smile:

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? :slight_smile:

You could give it a width, such as:

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.

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

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.

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. :slight_smile:

To get a beginning: