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.

Centering an image within the body

Featured Replies

Hi. Thinking of a new design, wondering if it's at all possible...

 

Imagine, for a second, you had a large image with a central point that was the focus. You wanted it applied to the body so the image takes up the whole page of a fixed, no scroll layout. The only problem is you want the centre point of the image to be in the centre of the browser window regardless of the size of the browser(with a minimum ofc). Kind of like when you use a #wrapper with margin: 0 auto;.

 

The image would have to shift outside of the browser window. Is that possible?

 

Hope it makes sense,

~evu.

body {background: url(your_image) top center no-repeat;}?

  • Author

I want to make the image suitable for 1024x768 as well as along the lines of 1900xW/E and I want the centre of the image to be in the centre of the browser.

 

With a #wrapper the margins disappear as you resize the browser window, keeping the container central. I want an image to do the same thing, keeping the centre point of the image, like the #wrapper, in the centre of the browser. This would force the sides of the image to have to disappear, like the margins, outside of the browser window.

 

Thanks Lev, I'm sure there's a reason that won't work, I just can't see it atm lol, it can't be that simple... Will try when I get home.

 

Cheers,

~evu.

lev's code is right, except it should be 'center center'. For this to work the image needs to be bigger than most monitors' resolutions.

 

e.g.

 

<html>
<head>

<style>
 body {margin:0;padding:0;background:url(path-to-img.jpg) no-repeat center center;}
 #wrp {width:960px;margin:0 auto;background:rgba(255, 255, 255, 0.;}
</style>

</head>
<body>

<div id="wrp"></div>

</body>
</html>

  • Author

lev's code is right, except it should be 'center center'. For this to work the image needs to be bigger than most monitors' resolutions.

 

e.g.

 

<html>
<head>

<style>
 body {margin:0;padding:0;background:url(path-to-img.jpg) no-repeat center center;}
 #wrp {width:960px;margin:0 auto;background:rgba(255, 255, 255, 0.;}
</style>

</head>
<body>

<div id="wrp"></div>

</body>
</html>

 

For some reason, when you don't initially specify the position in the css but try center center in Firebug it doesn't work. I tried center center first off, didn't work on top and bottom though.

 

But hey, it works now (or all along as the case may be...) :)

 

Cheers anyway!

~evu.

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.