Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning background image to right

Tags:

html

css

image

http://jsfiddle.net/Zx836/

In the second box, notice how the arrow is in the same place. How can I make it flow with the div?

Using scroll right center in the background property works but I want to keep some padding right.

I'm also trying to avoid using 2 divs or the tag. Is this possible just via the .box div?

like image 434
Cyber Junkie Avatar asked Dec 20 '10 01:12

Cyber Junkie


People also ask

How do I keep the background of a picture centered?

First, set a background image using the background-image property. Next, set the background-repeat property to no-repeat . Then, write the fixed option for the background-attachment property. After that, apply the background-position property to the center center option and the background-size property to cover .

How do you set a background image for margins?

You can't really add margins to a background image, since it's not actually an element. A couple things you might try: If you've got a containing element just inside the body, you can apply the background image to this element and set margins on it.

What is the correct way to set a background image?

The most common & simple way to add background image is using the background image attribute inside the <body> tag. The background attribute which we specified in the <body> tag is not supported in HTML5.


2 Answers

.right-align-background {
    background-position: center right;
}

http://jsfiddle.net/Zx836/1/

like image 61
Ben Avatar answered Sep 20 '22 07:09

Ben


You could also use background-origin: content-box; if your you would like your background to line up with the padding you set on the element.

Something like this:

input.error {
 background: no-repeat;
 background-image: url('../images/field-error.png');
 background-position: right center;
 background-origin: content-box;
 padding-right: 5px;
}
like image 26
Vlad Goran Avatar answered Sep 21 '22 07:09

Vlad Goran