40

HTML:

#backgroundproduct {
  position: fixed;
  top: 5%;
  left: 5%;
  width: 90%;
  height: 90%;
  z-index: 12;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  background-position: top;
}
<div id="backgroundproduct" style="background-image: url(http://example.com/example.jpg)">

I'm using a images as a background image, only the lower part of the image is more important than the top.

How can I make the background go up a little?

Adam
  • 1,385
  • 1
  • 10
  • 23
Ivo
  • 2,588
  • 6
  • 25
  • 43

3 Answers3

48

If the bottom is more important: background-position: bottom;

background-position also allows percentage values: 0% 0%; by default.

The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%.

You should try background-position: 0% -10%;

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
10

You can use:

background-position: center bottom;
Community
  • 1
  • 1
vivek
  • 1,944
  • 1
  • 17
  • 26
  • oke that's just stupid of my not thinking about this. thanks! – Ivo Dec 18 '12 at 00:45
  • You can use background-size: contain; to fit the background in div. Though, the image may look disproportionate because stretching may occur. This is a CSS3 property though. – vivek Dec 18 '12 at 00:50
  • 2
    `background-size: contain` maintains the bitmap's original aspect ratio – pmont Dec 24 '15 at 17:45
  • @pmont, but it doesn't cover the whole parent element. – Khom Nazid Sep 14 '19 at 16:58
  • Try `background-size: cover`. That's what I've used to cover the entire parent background. It stretches the bitmap if necessary while maintaining the original aspect ratio. – pmont Sep 16 '19 at 03:09
2

Just to be clear, background-position percentages are calculated against BOTH the image and the background container. So, background-position: 25% 25%; would find the 25% point for both X and Y on the background container and align the image's 25%,25% point on top of that point.

m b
  • 168
  • 1
  • 1
  • 7
  • If I specify pixel values,(x, y), will it find the (x, y) position on the image and set it to the containers (50%, 50%) position? – marcopolo Dec 29 '13 at 00:34