Fit website background image to screen size

2019-01-13 22:07发布

I'm just starting on a website and I already encounter a small problem where I can't find a specific solution to.

I wanted to make my website background fit any screen size in width, height does not matter.

This is the link to my image:

    ../IMAGES/background.jpg

EDIT

I have no idea what's wrong, but for some reason the body doesn't even want to get the background image. It just displays a plain white background.

body
{background-image:url(../IMAGES/background.jpg);}

11条回答
唯我独甜
2楼-- · 2019-01-13 22:25

Try this,

.appBg {

background-image: url(".../img/background.jpg");
background-repeat:no-repeat;
-webkit-background-size: 100% auto;
-moz-background-size: 100% auto;
-o-background-size: 100% auto;
background-size: 100% auto ;
}

This one works for me

查看更多
孤傲高冷的网名
3楼-- · 2019-01-13 22:26

Try this, I hope it will help:

position: fixed;
top: 0;
width: 100%;
height: 100%;
background-size: cover;
background-image: url('background.jpg');
查看更多
何必那么认真
4楼-- · 2019-01-13 22:38

You can do it like what I did with my website:

background-repeat: no-repeat;

background-size: cover;
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-13 22:40

You can try with

.appBackground {
    position: relative;
    background-image: url(".../img/background.jpg");
    background-repeat:no-repeat;
    background-size:100% 100vh;
}

works for me :)

查看更多
叼着烟拽天下
6楼-- · 2019-01-13 22:41

Background image fix to screens with browser compatibility css

.full-screen {
    height: 100%;
    width: 100%;
    background-image: url(../images/banner.jpg);
    background-size: cover;
    background-position: center;
    //for browser compatibility
    -moz-background-size: cover;
    -webkit-background-size: cover;
    -o-background-size: cover;
}
查看更多
登录 后发表回答