Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Easiest way to centre a background image?

Featured Replies

Hi folks, I was just wondering what the easiest way to centre a background image is? My image is a portrait of a friend and I want his head to be centered (horizontally) so that when viewed on small monitors it is still in the centre of the screen even tho the sides will be slightly out of view.

 

Thanks :)

I would stick it in a wrapper div and set the css to

#wrapper	{

width:1000px;			 
margin-left: auto;
margin-right: auto;							 
border: none;

}

 

No matter what the size, it will re-adjust :)

To make that even simpler:

 

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

  • Author

I read the first one and it seemed the easiest and it was. Thanks all. Thanks Wickham.

So the difference between the two approaches is one wraps to the screen size of the viewer and the other doesn't?

So the difference between the two approaches is one wraps to the screen size of the viewer and the other doesn't?

 

The difference is that if you center the background-image in the body, if the image is say 1280px wide it will center without leaving a space each side in most resolutions (only in resolutions above 1280px) while Helen's solution of putting a background image in a centered 1000px wide wrapper div is that it can never be more than 1000px wide which may leave spaces each side in modern screen resolutions.

 

If the background image is the same width as the wrapper you don't need to center the background image, only if it's less wide than the wrapper.

 

Use whichever method suits your page design.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.