search

Home  >  Q&A  >  body text

html - 如何用css令背景图能够撑满本身会滚动的页面?

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

PHPzPHPz2769 days ago592

reply all(5)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 11:36:40

    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

    reply
    0
  • PHPz

    PHPz2017-04-17 11:36:40

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

    reply
    0
  • 阿神

    阿神2017-04-17 11:36:40

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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 11:36:40

    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;
        }

    reply
    0
  • 阿神

    阿神2017-04-17 11:36:40

    body{ background:url(images/a-1.jpg) center no-repeat; background-size:cover;}

    reply
    0
  • Cancelreply