简体   繁体   中英

CSS: background-position: ???;

Hopefully these diagrams explain what I'm after. The red signifying the background and the grey the webpage.

Wrong

主持者imgur.com

Right

主持者imgur.com

How do I achive this? I've tried background-position: bottom right; but it's just all wrong.

background-position: right bottom; 

should do the trick.

Reference: CSS background-position Property

xpos ypos - The first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and positions

Works fine for me:

body
{ 
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:bottom right; 
}

And if the picture is big enough the no-repeat isn't needed. (Works even in IE6).

background-position: bottom right should indeed do what you describe.

If you want the image to stick to the bottom-right of the viewport rather than the document, you will have to add background-attachment: fixed . There are problems with this in IE, but when used on the main body/html background it's fine.

也许你忘了

background-position: absolute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM