How to properly implement the download background on the site with compliance with the extension of the visitor’s monitor?

That is, select the desired image for a specific extension.

Php site

3 answers 3

I think this will help media queries.

body { background-image: url("http://www.fullhdoboi.com/wallpapers/thumbs/6/kartinka-apelsiny-1885.jpg"); background-repeat: no-repeat; background-size: cover; } @media (max-width: 960px) { body { background-image: url("http://www.sunhome.ru/i/wallpapers/200/planeta-zemlya-kartinka.960x540.jpg"); } } 

     <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>РастягиваСмый Ρ„ΠΎΠ½</title> <style> body { background: url(images/Ρ„ΠΎΠ½.png) no-repeat; /* Π’Π°Ρˆ Ρ„ΠΎΠ½ Ρ‚ΡƒΡ‚ */ -moz-background-size: 100%; /* Firefox 3.6+ */ -webkit-background-size: 100%; /* Safari 3.1+ ΠΈ Chrome 4.0+ */ -o-background-size: 100%; /* Opera 9.6+ */ background-size: 100%; /* Π‘ΠΎΠ²Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Ρ‹ */ } </style> </head> <body> </body> </html> 

    When using background-size: 100% the background will occupy the entire width of the window (not the screen)

      corrected tags, here all the same basically JavaScript is needed, since php is a server technology.

      For example, output to php js an object or you can output as an attribute, for example, as an attribute:

        <div class="bg" data-bg="для ΠΌΠΎΠ±ΠΈΠ»ΠΊΠΈ ΠΊ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρƒ" data-bg-lg="ссылка Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ для экранов ΠΎΡ‚ 1200 ΠΊ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρƒ" data-bg-md="ссылка Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ для экранов ΠΎΡ‚ 970"></div> 

      this way it is possible for any permissions, and then on js handler, I will write using jQuery, the logic should be clear anyway

       $(window).on("load resize scroll",function(e){ var width = $(window).width(), $blockBg = $('.bg'), image = $blockBg.attr('data-bg'); if(width > 970 && width < 1200) { image = $blockBg.attr('data-bg-md'); } if(width > 1200) { image = $blockBg.attr('data-bg-lg'); } $blockBg.css('background', 'url('+image+')'); } 
      • The Apple Vine version is also correct, but it happens that at different resolutions the images should not change much due to the content area, etc. - maxkrasnov