Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the background-position to an absolute distance, starting from right? [duplicate]

Tags:

css

I want to set a background image for a div, in a way that it is in the upper RIGHT of the div, but with a fixed 10px distance from top and right.

Here is how I would do that if wanted it in the upper LEFT of the div:

background: url(images/img06.gif) no-repeat 10px 10px;

Is there anyway to achieve the same result, but showing the background on the upper RIGHT?

like image 214
bahadorn Avatar asked Sep 22 '08 12:09

bahadorn


People also ask

How do you get an absolute background-position?

The correct format is: background: url(YourUrl) 0px -50px no-repeat; Where 0px is the horizontal position and -50px is the vertical position. CSS background-position accepts negative values.

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

Create a div containing the image. Explicitly set the position of the containing element position: relative if not already set. Set the image container to position: absolute; right: 10px; top: 10px; , obviously adjusting the final two as you see fit. Place the image div container into the containing element.

How do you set absolute position in HTML?

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.

How do you position absolute elements?

Absolute An element with position: absolute is removed from the normal document flow. It is positioned automatically to the starting point (top-left corner) of its parent element. If it doesn't have any parent elements, then the initial document <html> will be its parent.


1 Answers

In all modern browsers and IE down even to version 9 you can use a four-value syntax, specified in CSS3:

background-position: right 10px top 10px; 

Source: MDN

like image 117
Boldewyn Avatar answered Sep 21 '22 20:09

Boldewyn