html - 如何用css令背景图能够撑满本身会滚动的页面?
PHPz
PHPz 2017-04-17 11:34:40
0
5
597

使用height:100%和background-size:100%的话只是屏幕可见区域撑满,如何能够让滚动到下方区域也能够撑满?
补充一下是移动端的,并且背景图需要同时滚动,楼下的cover方法试过还是不行

PHPz
PHPz

学习是最好的投资!

reply all(5)
左手右手慢动作

Try using the css3 attribute background-size:cover, which adapts to the screen by default and will stretch the image.
Supplement: If it is a mobile version, such as:

It has been tested and the effect can be viewed on mobile phones - link: http://yulei521.github.io/input_autofocus/background .html

PHPzhong

background-attachment:fixed;
Fix the background image so it doesn’t move when you scroll!

阿神

There are many ways to achieve this. In addition to the two methods above, there is also the simplest position: fixed

伊谢尔伦

This can be achieved and has been tested. However, background-size has compatibility issues and is not compatible with IE6 (7|8). You can try it specifically

   body{
        background: url(img/Koala.jpg) no-repeat;
        background-size: cover;
    }
阿神
body{ background:url(images/a-1.jpg) center no-repeat; background-size:cover;}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template