-2

I have an image called myImage.jpg. This is my CSS:

body {
    background-image:url("../images/myImage.jpg");
    background-repeat: no-repeat;
    margin: 0px auto;
}
#header {
    width: 640px;
    background-color: red;
    margin: 0px auto;
}

This made the height of myImage.jpg 100% of the screen and made the width 640px, but it did not center myImage.jpg. myImage.jpg is completely to the left.

How do I center myImage.jpg?

SilentDev
  • 20,997
  • 28
  • 111
  • 214
  • https://developer.mozilla.org/en-US/docs/Web/CSS/background-position – Quentin Apr 05 '14 at 22:30
  • Flag! You just asked a similiar question here http://stackoverflow.com/questions/22887548/css-stretching-background-image-to-100-width-and-height-of-screen, would it have been so hard to ask this along with the same question! – T J Apr 05 '14 at 22:33
  • @TilwinJoy I though on SO you should only ask one question per post.. SO isn't a 'ask a question, get it answered, ask another question in the same post'. Plus, for further use, it'd be much easier for other people who have the same issue to search and find this issue when it is in it's own post, rather than being hidden in another post. And on top of that, when I created the other question, I didn't even have this question in mind. This question came up after the other question was answered.. Thanks for the downvote though, appreciate it :) – SilentDev Apr 05 '14 at 22:36
  • This question is a possible duplicate of http://stackoverflow.com/questions/2643305/centering-a-background-image-using-css and lots and lots of other questions, plus you're posting questions within minutes that simply requires 1 line answer which you can find from a google search! One question - 1 answer is really appropriate for questions that'll require some effort though. – T J Apr 05 '14 at 22:39

1 Answers1

3

add a background-position: center 0%; to the body rules

Billy Moon
  • 57,113
  • 24
  • 136
  • 237