Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set fixed background position from right side in css? [duplicate]

Tags:

css

In this case

li {background: url("../img/grey-arrow-next.png") no-repeat right center;     border-bottom: 1px solid #D4E8EB} 

I want 20px space in right side before to background image and I can't give margin on li because border should touch the edges.

So I need to set 20px but it takes 20px from left side not right side.

li {background: url("../img/grey-arrow-next.png") no-repeat 20px center;         border-bottom: 1px solid #D4E8EB} 
like image 454
Jitendra Vyas Avatar asked Apr 20 '11 13:04

Jitendra Vyas


People also ask

How do I move a background image to the right in CSS?

Give it a shot. Essentially, background-position: 90% 50% will make the right edge of the background image line up 10% away from the right edge of the container. Create a div containing the image. Explicitly set the position of the containing element position: relative if not already set.

How do I create a fixed background in CSS?

To keep your background fixed, scroll, or local in CSS, we have to use the background-attachment property. Background-attachment: This property is used in CSS to set a background image as fixed or scroll. The default value of this property is scroll.

Which CSS property is used when we want to position the background image in the right at the top of the Web page?

The background-position CSS property sets the initial position for each background image. The position is relative to the position layer set by background-origin .

Which property of CSS is used to make background fixed?

The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.


2 Answers

in your css mention position right then "spacing value(50px)" then other position(center/top)

li {background: url("../img/grey-arrow-next.png") no-repeat right 50px center; border-bottom: 1px solid #D4E8EB} 

Older Browser and IE8 and old version of IE does not support this code. Latest updated browsers has no conflicts with this method and hopefully future updates will support it too.

If you are using modern browser, try background-position: calc(100% - 50px) center; as suggested in another answer too. calc has long way to go as it is logically and mathematically capable to produce much accurate result.

like image 110
Nizam Kazi Avatar answered Sep 19 '22 14:09

Nizam Kazi


You can use the CSS3 "calc" function:

example:

background-position: calc(100% - 10px) center; 
like image 33
Danny Coulombe Avatar answered Sep 22 '22 14:09

Danny Coulombe