Skip to content

Instantly share code, notes, and snippets.

@Patrick64
Last active November 28, 2018 15:29
Show Gist options
  • Save Patrick64/56eb13e07b38817b5b906c88410d0c21 to your computer and use it in GitHub Desktop.
Save Patrick64/56eb13e07b38817b5b906c88410d0c21 to your computer and use it in GitHub Desktop.
Tempalte snippet for making a response image background to minimise download size using CE Image. #eecms
{!--
Template snippet image_bg_css.html
This tempalte snippet is for making a response image background to minimise download size using CE Image.
Usage:
{embed="include/image_bg_css" class="div-class" src="{image_url}" max="800"}
^ ^ ^ ^
| | | |
location of this template Class of div URL of image Max image size
<div class="div-class"> This div has the background </div>
Needs CE Image and modified Math eecms addon here https://github.com/Patrick64/math
--}
<style>
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 1' formula='568 * 1'}"});
}
@media (min-resolution: 2dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} *2' formula='568 * 2'}"});
}
}
@media (min-resolution: 3dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} *3' formula='568 * 3'}"});
}
}
@media (min-width: 569px){
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 1' formula='768 * 1'}"});
}
}
@media (min-width: 569px) and (min-resolution: 2dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 2' formula='768 * 2'}"});
}
}
@media (min-width: 569px) and (min-resolution: 3dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 3' formula='768 * 3'}"});
}
}
@media (min-width: 769px){
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 1' formula='1024 * 1'}"});
}
}
@media (min-width: 769px) and (min-resolution: 2dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 2' formula='1024 * 2'}"});
}
}
@media (min-width: 769px) and (min-resolution: 3dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 3' formula='1024 * 3'}"});
}
}
@media (min-width: 1025px){
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 1'}' formula='1366'}"});
}
}
@media (min-width: 1025px) and (min-resolution: 2dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 2' formula='1366 * 2'}"});
}
}
@media (min-width: 1025px) and (min-resolution: 3dppx) {
/* styles for Retina-type displays */
.{embed:class} {
background-image:url({exp:ce_img:single parse='inward' src='{embed:src}' url_only='yes' max_width="{exp:math max='{embed:max} * 3' formula='1366 * 3'}"});
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment