简体   繁体   English

如何设置背景图片

[英]How To Set Background Image

I need to set this background image in my website for chrome and all other browser but in chrome it work perfect but in firefox and other browser doesn't work perfectly. 我需要在我的网站上为chrome和所有其他浏览器设置此背景图片,但是在chrome中,它可以正常运行,但在Firefox和其他浏览器中却无法正常运行。 Even for firefox I tried the -moz- tag but doesn't work. 即使对于Firefox,我也尝试了-moz-标记,但是不起作用。

{
    position: relative;
    background:url(backgrdnd2.jpg);
    background-repeat:no-repeat;
    -moz-background-size:100% 100%;
    background-size:100% 100%;
}

try backgroud-size:cover; 尝试backgroud-size:cover;

-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size:cover;
background-size: cover; 

for the rest of the browsers 对于其余的浏览器

hope it helps. 希望能帮助到你。

The background property is supported in all major browsers. 所有主要浏览器均支持background属性。 See: http://www.w3schools.com/cssref/css3_pr_background.asp 请参阅: http//www.w3schools.com/cssref/css3_pr_background.asp

I'm not sure what element you are applying these styles on, but perhaps that element has no height or width? 我不确定要在哪些元素上应用这些样式,但是也许该元素没有高度或宽度? Try inspecting the element in Chrome or using Firebug in Firefox to determine if your background image is loading, and whether or not the element you are applying the background to is visible. 尝试检查Chrome中的元素或在Firefox中使用Firebug,以确定是否正在加载背景图片,以及是否将应用背景的元素可见。

First, in your css you should put the selector, where do you want to apply the style, for example the body 首先,在CSS中,应将选择器放在要应用样式的位置,例如主体

body {
    position: relative;
    background:url(http://2.bp.blogspot.com/-m7blv8kfKxs/UiAWmV9uJXI/AAAAAAAAJos/RsYP_YC9FbY/s1600/Background-Textures2.jpg);
    background-repeat:no-repeat;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size:cover;
    background-size: cover;
}

check this link for more information about selectors. 检查此链接以获取有关选择器的更多信息。

http://www.w3schools.com/cssref/css_selectors.asp http://www.w3schools.com/cssref/css_selectors.asp

I also used @EduadoRobles suggestion, check this 我也用过@EduadoRobles建议,检查一下

http://jsfiddle.net/agusgambina/A8nmp/ http://jsfiddle.net/agusgambina/A8nmp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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