简体   繁体   中英

Background image doesn't show in firefox and IE

I'm new to bootstrap and overall web design. Using the original bootstrap.css and the bootstrap's default html file, I added this as my custom css :

 body {
    margin: 0;
    background: url("some image url");
    background-position: center top;
    background-size: 1440px 800px;
    background-repeat:no-repeat;
    display: compact;
}

and it works fine on chrome but it doesn't show up on IE or firefox. Using firebug I inspected the css and got this :

body {
   background: url("some image url") repeat scroll center top / 1440px 800px rgba(0, 0, 0, 0);
   margin: 0;
  }

But I still can't figure out where the problem is. Is there any other way to write the simple CSS snippet so IE and firefox can work with it?

edit : I fixed the semi colon issue but still not showing up. Firebug showing :

body {
margin: 0;
background: url("some image url");
background-position: center top;
/* background-size: cover; */
background-size: 1440px 800px;
background-repeat:no-repeat; 
display: compact;
  }

EDIT : I had to put the direct path to the image vs using a url. Thank you all for your suggestions and help!

http://www.w3schools.com/css/css_background.asp

You need to change

background: url("some image url");

into

background-image: url("some image url");

您好@tyrell_c我认为问题可能是Firefox不支持“ display:compact”,也请尝试省略图片网址中的引号

好吧,所有其他答案都很好,我总是使用它们,但是如果它们不起作用,您可能会做一个简单的技巧,例如在刚开始的身体上添加img,并将其高度和宽度设置为100%,以使照片成为根据屏幕尺寸做出响应。这将拉伸照片,并且对用户而言将像背景照片一样,因为它看起来相同

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