How to use CSS media query to scale background-image to viewing window

后端 未结 1 566
猫巷女王i
猫巷女王i 2020-12-15 14:15

I have this large image as a background for a website:

body {
    background: #000 url(/assets/img/living.jpg) no-repeat center center;
    background-attach         


        
相关标签:
1条回答
  • 2020-12-15 14:19

    Try this - you don't always need a media query to handle background images. The CSS3 background-size:cover property handles all that quite well on its own. The below works well for me on all mobile devices I've tested - especially well on Android, mobile version browsers and all tablets.

    body { 
        background-image: url(/assets/img/living.jpg); 
        background-repeat: no-repeat; 
        background-position: center;
        background-attachment: fixed;       
        webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        height:100%;
        width:100%; 
    }   
    
    0 讨论(0)
提交回复
热议问题