Fluid images, responsive web design and CMSB
2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 4, 2013 (RSS)
By JeffC - February 4, 2013
I am embarking on my first venture into responsive web design. All is good until I come to load images. The general advice I've found on the web is to use max-width:100%:
img {
max-width: 100%;
}
For me, while it works, this is not the best solution because you are scaling images in the browser. Scaling a 1000px image to 100px isn't ideal for someone on a mobile device on 3G
I have adopted a mobile first strategy using the following media queries for larger screen sizes:
@media only screen and (min-width: 481px) {
}
@media only screen and (min-width: 769px) {
}
And now to the question...
How do I serve a different image to different screen sizes using php within the cmsBuilder code. Could I use an IF clause to load thumb1 for default, thumb2 for min-width 481px, and thumb 3 for min-width 769px. If so how? If possible I would like the solution to avoid javascript to avoid calling additional files.
Hi,
As PHP isn't capable of knowing the screen resolution of the user who has requested the page, you will have to use Javascript to change the image that is being used.
You could give this plugin a try, it uses a mix of Javascript and PHP to resize images on the fly, but it does look as if it might be fairly resource intensive:
Another better looking solution is hisrc:
https://github.com/teleject/hisrc
If you download this plugin and look at the breakpoint demo, you can see how it would be possible to use the thumbnails generated by CMS Builder for smaller images.
Thanks!
Greg
PHP Programmer - interactivetools.com