they are generated into a single sprite, and then they are base64-encoded to be rendered inline with the CSS file. It’s a larger hit initially, but the fewer http requests the better. Thursday, April 18, 13
pixel positions even - remove the fuzz • Can have 2 versions - responsive device pixel ratio • Let javascript do it for you - http:// retinajs.com/ Thursday, April 18, 13
as separate files, put them in a sprite. 1. Create a 2x version of your asset sprite that is exactly double the size, and has the different assets at exactly double the dimensions inside of the sprite. 2. Gather all the selectors that reference the sprite, and reference them towards the @2xsprite within the media query for high-resolution displays. 3. Make sure you don’t forget to set the background-size property to translate the dimensions of the @2x sprite. Thursday, April 18, 13
verbose -be sure to optimize the output • font icon libraries • font awesome - http:// fortawesome.github.io/Font-Awesome/ • fontello - http://fontello.com/ Thursday, April 18, 13
> # of DOM elements, the slower that both CSS and JS performs, as they both ‘traverse the DOM’ • Try some layout utilities to help condense your code - http://yuilibrary.com/ • console.log(document.getElementsByTagName('*').length) Thursday, April 18, 13
letters, numbers, and a hyphen) • Both must begin with a letter • The name should represent the function and not the appearance • Zen and the Art of Motorcycle Maintenance Thursday, April 18, 13
surface appeal without considering classical underlying form.” - Zen and the Art of Motorcycle Maintenance • Excellent book that uses the motorcycle as a metaphor to discuss philosophical ideas • The hippies are romantics that just ride the motorcycle. The squares are the ones that are concerned with how it functions and tinkering with the machines. • Sounds like designers vs. developers? :-) Thursday, April 18, 13
unique (1 per page) • excellent hooks for JavaScript (slight performance eval) • 255x more powerful than a class ( http:// codepen.io/chriscoyier/pen/lzjqh) Thursday, April 18, 13
Snook - worked for Yahoo, Shopify • Built 100s of websites • Proposes the essential question: • “How do you decide whether to use ID selectors, or class selectors, or any number of selectors that are at your disposal? ” Thursday, April 18, 13
almost exclusively single element selectors but it could include attribute selectors, pseudo-class selectors, child selectors or sibling selectors. Essentially, a base style says that wherever this element is on the page, it should look like this. body { margin:0;padding:0;} h1 { color: #333; margin: 0; text-decoration: underline; border: solid 1px #000; } a { text-decoration: none; } a:hover { text-decoration: underline;} Thursday, April 18, 13
• callout box • store catalog (products) • sidebar content • Ideally you should be able to paste these anywhere in your site and they function as expected - that’s modular code Thursday, April 18, 13
state - is it visible? hidden? selected? highlighted? expanded? contracted? error? success? • Site position state - home page? checkout page? Thursday, April 18, 13
and evaluates from there (looks to find a match) • Browsers read CSS from right to left • img#1 > p.important, div > img, p a • Key selectors would be p, img, a Thursday, April 18, 13
specific, I prefer to say succinct ( don’t use Id’s ) • Rather than this: • div.image-assets div.col-one img { float: left;} • just use this: • .image-asset { float: left; } Thursday, April 18, 13
Mozilla, the descendant selector is the most expensive selector in CSS! Use the child selector instead. • Browser read css from right to left, so with descendant selectors the entire document is scanned several times • .three-col .col-one .aside { width: 180px; } Thursday, April 18, 13
the scope of evaluation • element must be a direct child of the parent element (not nested) • .three-col > .col-one > .aside { width: 180px } -- still not very optimized, but better than descendants Thursday, April 18, 13
descendant selectors, it’s not a panacea. • Especially avoid it with tag/selector rules. This will dramatically increase page rendering time. • Again, just keep it succinct. • One child, level, used sparingly. Avoid more. Thursday, April 18, 13
the formatting, then don’t apply it to the child • Less evaluations, better performance • ul li { list-style-type: none; } • ul { list-style-type: none; } Thursday, April 18, 13
the classes to represent objects (semantic) • use multiple classes to keep repetition low • you can still use Id’s (for Javascript hooks) Thursday, April 18, 13