I have a main page with a big background image in background. File is 1600x815 px and 191kb. I guess is acceptable for a destkop pc, but I’ d like to have and serve smaller images (versions of the same image), so that users accessing my website with tablets or cellphones receive a lighter version of that background image ok?
The .css file has this:
#banner {
background-attachment: scroll, scroll, scroll, fixed;
background-color: #645862;
background-image: url("images/light-bl.svg"),
url("images/light-br.svg"), url("images/overlay.png"),
url("../../images/banner.jpg");
background-position: bottom left, bottom right, top left, top center;
background-repeat: no-repeat, no-repeat, repeat, no-repeat;
background-size: 25em, 25em, auto, cover;
color: #fff;
cursor: default;
padding: 6em 0;
text-align: center;
}
The important one is the one called “banner.jpg”, that’s the big image on background I started talking about.
(the other files are simple thin lines to condiment the design)
I made this versions of my background image:
- banner.jpg (1600x815)
- banner1200.jpg (1200x611)
- banner640.jpg (640x326)
- banner320.jpg (320x163)
- bannerhd.jpg (1600x815 this one has almost no compression so better quality image than my original banner.jpg)
In my html page, the code has this tag
<section id="banner"></section>
I belive (and I’m not an expert) that, this is the part who calls the image from the css file.
The big question is:
How do I do to “serve” banner640.jpg, or banner320.jpg and so on, depending on page be accessed by a cellphone, tablet, etc
A sample code would be great!
Thank you in advance!