如何在右下角定位背景图像?(CSS)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7729652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 01:52:06  来源:igfitidea点击:

How to position background image in bottom right corner? (CSS)

cssbackground

提问by Ilja

I have a 500x500 px image which is set as a background image on my website (as background-image of <body>) But I need this image to be located in a bottom right corner of the webpage. How can I achieve this? (better with css method)

我有一个 500x500 像素的图像,它在我的网站上设置为背景图像(作为 的背景图像<body>)但我需要将此图像放置在网页的右下角。我怎样才能做到这一点?(用 css 方法更好)

Thank You.

谢谢你。

回答by Rob W

Voilà:

瞧:

body {
   background-color: #000; /*Default bg, similar to the background's base color*/
   background-image: url("bg.png");
   background-position: right bottom; /*Positioning*/
   background-repeat: no-repeat; /*Prevent showing multiple background images*/
}

The background properties can be combined together, in one background property. See also: https://developer.mozilla.org/en/CSS/background-position

背景属性可以组合在一起,在一个背景属性中。另见:https: //developer.mozilla.org/en/CSS/background-position

回答by Arthur Tsidkilov

for more exactly positioning:

更准确的定位:

      background-position: bottom 5px right 7px;

回答by Arthur Tsidkilov

This should do it:

这应该这样做:

<style>
body {
    background:url(bg.jpg) fixed no-repeat bottom right;
}
</style>

http://www.w3schools.com/cssref/pr_background-position.asp

http://www.w3schools.com/cssref/pr_background-position.asp

回答by markt

Did you try something like:

你有没有尝试过:

body {background: url('[url to your image]') no-repeat right bottom;}