CSS - background-size: cover; not working in Firefox

ぃ、小莉子 提交于 2019-12-07 00:55:31

Well it looks alright to me in latest mozilla.

Try using this if you face problems

body { 
  background: url("./content/site_data/bg.jpg") no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  font-family: 'Lobster', cursive;
}

Edit

As some more clearance of answer to OP from comments

background: url("./content/site_data/bg.jpg") no-repeat center center fixed;

Its shorthand for,

background-image: url("./content/site_data/bg.jpg");
background-repeat:no-repeat;
background-position: center center;
background-attachment:fixed;

Read more here

So I just came across this question because I was having the same problem. It turned out the issue (in my case anyway) was not having

<!DOCTYPE html>

at the top of my html file (this only seemed to affect the background-size: cover in Firefox.

background-size was added to Firefox 3.6, however the -moz vendor prefix was required.

use

-webkit-background-size: 100% 100%;           /* Safari 3.0 */
     -moz-background-size: 100% 100%;           /* Gecko 1.9.2 (Firefox 3.6) */
       -o-background-size: 100% 100%;           /* Opera 9.5 */
          background-size: 100% 100%;           /* Gecko 2.0 (Firefox 4.0) and other CSS3-compliant browsers */

bhawal, I think you are using older version of mozilla. Well, this is a common practice to add vendor specific prefixed properties together with W3 standard. We do this just to make sure that it work in most of the browsers. In your case, you can use the CSS rule below:

body { 
  background: url(images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

Let me know, if this doesn't work; and vote up if it works. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!