Stretch and scale a CSS image in the background - with CSS only

后端 未结 22 2526
迷失自我
迷失自我 2020-11-22 01:37

I want that my background image stretch and scale depending on the browser viewport size.

I\'ve seen some questions on Stack Overflow that do the job, like

22条回答
  •  不知归路
    2020-11-22 01:48

    Thanks!

    But then it was not working for the Google Chrome and Safari browsers (stretching worked, but the hight of the pictures was only 2 mm!), until someone told me what lacks:

    Try to set height:auto;min-height:100%;

    So change that for your height:100%; line, gives:

    #### #background {
        width: 100%; 
        height: 100%; 
        position: fixed; 
        left: 0px; 
        top: 0px; 
        z-index: -1;
    }
    
    .stretch {
        width:100%;
        height:auto;
        min-height:100%;
    }
    

    Just before that newly added code I have this in my Drupal Tendu themes style.css:

    html, body{height:100%;}

    #page{background:#ffffff; height:auto !important;height:100%;min-height:100%;position:relative;}

    Then I have to make a new block within Drupal with the picture while adding class=stretch:

    < img alt="" class="stretch" src="pic.url" />

    Just copying a picture with the editor in that Drupal block doesn't work; one has to change the editor to non-formatted text.

提交回复
热议问题