Grow your CSS skills. Land your dream job.

How to centre a Background image

  • # March 1, 2013 at 9:25 am

    Hi New here and to CSS. I have looked everywhere but can’t find or work out how to centre a background image.
    I have a header and want to use an image as the background. I have set the background image and tried using left and right margin as auto. However the image always goes to the left. I want to use it for a mobile site, and just need a small image to be in the centre. I am using Dreamweaver CS6 on a mac.

    Any help would be appreciated.

    # March 1, 2013 at 9:51 am

    You should try this:

    element(your header) {
    background: url(imagepath/bg.png) no-repeat center center;
    }

    # March 1, 2013 at 10:27 am

    Many thanks….. you’re a genius

    # March 1, 2013 at 6:42 pm

    [You might also look at this implementation](http://css-tricks.com/perfect-full-page-background-image).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".