-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Responsive Media in HTML5
By :

If you have spent any time working with media in a responsive capacity, no doubt you will find that some image formats don't resize well. To get around it, it may be necessary to provide several different versions of our image and set the code to pick the right one at the appropriate point.
Do we want to be doing that all the time? Somehow I don't think so. It's a real pain to produce all those different versions! There's a better way to achieve the same result if we switch to using the vector-based SVG format, which will resize smoothly without loss of quality. Let's delve into an example to see how it works:
svgfallback.html
in the root of our project folder:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/svgfallback.css"> </head> <body> This is an image displayed using SVG, with PNG fallback: <br> <div id="lcd"></div> </body> </html>
svgfallback.css
in the css
subfolder of our project folder:#lcd { background: url('../img/lcd.png'); background-image: url('../img/lcd.svg'), none; width: 576px; height: 383px; background-repeat: no-repeat; }
The beauty of using SVG is that we can actually edit the content of the image using a text editor; SVG images are after all just plain XML files! SVG images are great for several reasons:
Using standard images such as PNGs or JPGs will work, but they won't resize properly beyond their native resolution; instead, we are likely to need several versions of the same image in order to view them properly. It's worth spending time getting to know the SVG format. There is a useful article by Nick Salloum at http://callmenick.com/2014/04/02/svg-fallback-with-png/, which extols different mechanisms we can use to provide fallback for SVG images.
If you really want to get into editing SVG images, take a look at http://css-tricks.com/using-svg/. It's a great article by Chris Coyier that shows us how we can edit the content to really alter its appearance.
Change the font size
Change margin width
Change background colour