0

Possible Duplicate:
Offset a background image from the right using CSS

CSS usually is :

background-position:right top; 

but If I'd like to say somethings like right-5px? Is it possible? Like position in an element :

right:-5px;

Anyone know?

EDIT

Maybe it is unclear! I mean somethings like :

background-position:right-5px top; 
Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

2

http://www.w3.org/TR/CSS21/colors.html#propdef-background-position

As of CSS2.1 specs, you only can do this if you know the dimensions of the container.

Assume container is 300px. you can either say:

background-position:305px or use percentages.

However,

http://www.w3.org/TR/css3-background/#the-background-position

as of the css3 specs, you can define the offsets from all different corners.

So background-position: top 0 right -5px; would give your desired result.

Except IE, Support is quite good.

Christoph
  • 50,121
  • 21
  • 99
  • 128
1

It's not possible with CSS2 but you can do a trick. Write like this:

div{
    background:red;
    width:200px;
    height:200px;
    position:relative;
    overflow:hidden;
}
div:after{
    content:'';
    position:absolute;
    width:200px;
    height:200px;
    top:0;
    right:-5px;
    background:url('http://www.dummyimage.com/600x400/000/fff');
}

Check this http://jsfiddle.net/s9L2T/

sandeep
  • 91,313
  • 23
  • 137
  • 155