On Github startinggravity / picture-perfect-drupal
Presented: July 31, 2014 - Capital Camp and Gov Days '14 August 23, 2014 - Drupal Camp Asheville 2014 September 13, 2014 - Drupal Camp Chattanooga 2014 October 4, 2014 - Drupal Camp Atlanta 2014
This session will be repeated at the Chattanooga Drupal camps.This presentation can be found athttp://startinggravity.github.io/picture-perfect-drupal
Download a copy of the presentation to get the links. [view survey]img { max-width: 100%; }
Except... This won't work on IE 6 or 7
http://sassmeister.com/gist/startinggravity/4f7f692eb60e92c23ece
To make an image fit any device, make it scalable. Fortunately, just a little bit of CSS will make that happen. Setting max-width to 100% ensures the image does not scale larger than its actual size and it will be constrained by the container around it. [reveal] This CSS won't work on IE 6 or 7.img { width: 100%; }Use width 100% on IE 6 and 7 if you must design for those browsers.
img { max-width: 100%; }Looking at our easy solution we see the problem: We're treating every image the same, regardless of where it appears.
Display Size
We should never try to load images that are larger than necessary.Pixel Density
We also need to understand that some displays are capable of handle high density images. An image with a 2x multiplier will have four times the number of pixels.A media type and zero or more expressions that define a style sheet's scope. These may be such things as width, height, color or resolution.
Best practice: Media queries are hard to keep track of unless you use a CSS preprocessor.@media (max-width: 50.875em) { .links a { display: block; font-weight: 400; height: 70px; color: red; } } @media (max-width: 68.75em) { .links a { height: 90px; color: blue; } }
A defined point in the display where we want to make stuff change, such as the size and position of text and images, and the number of columns.
Best practice: Don't set breakpoints according to devices. When the page looks bad at a certain size, add a breakpoint.A number indicating the increased total of pixels displayed in an image compared to a standard image.
Best practice: Enlarge the orginal image by the multiplier. What matters is number of pixels.A preprocessed language to parse code into CSS. This allows for variables, selector inheritance and other shorthand methods to be used to speed up coding and make the CSS more flexible.
Best practice: Use SCSS, a newer version of Sass.Extends the use of Sass by providing reusable patterns.
Best practice: Use Compass extensions to simplify your workflow and and make Sass do things it can't do on its own.<picture> <!--[if IE 9]> <video style="display: none;"><![endif]--> <source srcset="images/extralarge.jpg" media="(min-width: 1000px)"> <source srcset="images/large.jpg" media="(min-width: 800px)"> <!--[if IE 9]></video><![endif]--> <img src="images/medium.jpg" alt="A picture"> </picture>Here is an example of code that Picturefill polyfill (and therefore, Picture module) can use. The will now recognize the use of the picture, srcset and src in your markup.
Using these modules with Image Styles allows you to select images of different sizes for your breakpoints.
You don't always want images in the same size ratio, and using Image Styles allows you to change that, as well as the size.Trigger the use of high-density images.
High-density versions can be created automatically with Image Styles.
Start with a standard size. Create another the same size and then increase the size by multiplying the dimensions with the multiplier.Define breakpoints first
@import "breakpoint"; @import "compass"; // min-width (by default) if only a number $breakpoint-hamburger: 20em; // 320px $breakpoint-tabs: 36.250em; // 580px $breakpoint-twocolumn: 56.25em; // 900px $breakpoint-fullfeatures: 68.75em; // 1100px
If you use Sass, use the Breakpoint Compass extension.
Use breakpoint variables that are meaningful.Set breakpoints in theme.info
; ======================================== ; Breakpoints ; ======================================== breakpoints[fullfeatures] = (min-width: 68.75em) multipliers[fullfeatures][] = 1.5x multipliers[fullfeatures][] = 2x breakpoints[twocolumn] = (min-width: 56.25em) multipliers[twocolumn][] = 1.5x multipliers[twocolumn][] = 2x breakpoints[tabs] = (min-width: 36.250em) multipliers[tabs][] = 1.5x multipliers[tabs][] = 2x breakpoints[hamburger] = (min-width: 20em) multipliers[hamburger][] = 1.5x multipliers[hamburger][] = 2x
Breakpoint order should be largest to smallest.
This will mess with your configuration if you do it wrong.Breakpoints in theme.info will load automatically
Clear cache to see breakpoints in the configuration page.
Map images to breakpoints and multpliers
Map images to breakpoints and the multipliersDone correctly, the right image for the display size and pixel density will be delivered.
Any image that should be uploaded and applied on the fly should use these modules.Not every image is a photo, butevery image needs to be handled responsively.
A little misleading. Always use Picture and Breakpoints, but not ever image can be used in this way.Several small images combined into a single image, then a portion of the image is selected for display through CSS.
This technique has been around a long time..stars-half, .stars-one, .stars-one-half, .stars-two, .stars-two-half, .stars-three, .stars-three-half, .stars-four, .stars-four-half, .stars-five, .stars-none { background-image: url("../images/sprite.png"); background-repeat: no-repeat; display: inline-block; } .stars-half { background-position: 0 0; height: 17px; width: 8px; } .stars-one { background-position: -10px 0; height: 17px; width: 16px; } ...This is just example code. There is a lot more that goes into displaying these stars.
Use Compass and Sass to make your sprites on the fly!
Clean, resizable icons that can be usedregardless of browser or pixel density
Icon fonts are treated the same way as any font.http://sassmeister.com/gist/startinggravity/70cb05adac7d5f386d1c
Online tools let you create a custom set from multiple libraries.
All the advantages of icon fontswith the convenience of a Drupal module.
Several ways to use
This example shows just one way to use the Font Awesome module.They're convenient and flexible,but they miss the mark for most logos.
That's when you need vector (SVG) images.
<img src="logo.svg" alt="my logo">
$hidpi: min-resolution 1.5dppx; $cross-reso: max-resolution 143dpi; #foo{ @include breakpoint($hidpi){ content:'Device Pixel Ratio of at least 1.5'; } @include breakpoint($cross-reso){ content:'Cross Browser Resolution Query' } }
Device pixel density tests
Can I Use _____ ?