03.12.2012 Views

Making the hard stuff fun & easy with YUI CSS

Making the hard stuff fun & easy with YUI CSS

Making the hard stuff fun & easy with YUI CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

If you can’t read this, move closer<br />

<strong>Making</strong> <strong>the</strong> <strong>hard</strong> <strong>stuff</strong><br />

<strong>fun</strong> & <strong>easy</strong> <strong>with</strong> <strong>YUI</strong> <strong>CSS</strong><br />

Vani Raja<br />

vani@webchic.net<br />

http://webchic.net/talks/yui/<br />

OSCON ’07<br />

r7


<strong>YUI</strong> <strong>CSS</strong>: Why It Rocks<br />

★ A handful of predefined styles that will rock<br />

your world.<br />

★ Over 750 page layout possibilities in under 3<br />

minutes – minimal html changes!<br />

★ A-Grade browser support (supported and tested by<br />

Yahoo)<br />

★ Normalize all HTML elements to ensure<br />

similar display across browsers.<br />

★ Customized table-less page layouts in 10<br />

minutes, <strong>with</strong>out two Advil.


Basic <strong>CSS</strong> terminology<br />

★ div – html element<br />

Essential building block of your<br />

layout.<br />

★ id – selector<br />

One unique per page. Like your driver’s license.<br />

#header, <br />

★ class –selector<br />

Up to many per page.<br />

.caption, <br />

http://flickr.com/photos/randomlyhumming/247604167/


The Files<br />

★reset.css<br />

normalizes margins, padding, etc.<br />

★fonts.css<br />

sets font baseline & even scaling<br />

★grids.css<br />

defines classes for preset height<br />

and widths of div html elements


eset.css<br />

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h<br />

6,pre,form,fieldset,input,textarea,p,blockq<br />

uote,th,td {margin:0;padding:0;}<br />

table {border-collapse:collapse;borderspacing:0;}<br />

fieldset,img {border:0;}<br />

address,caption,cite,code,dfn,em,strong,th,<br />

var {font-style:normal;font-weight:normal;}<br />

ol,ul {list-style:none;}caption,th {textalign:left;}<br />

h1,h2,h3,h4,h5,h6 {font-size:<br />

100%;font-weight:normal;} q:before,q:after<br />

{content:'';}abbr,acronym {border:0;}


what reset does<br />

★ starts <strong>with</strong> everything normalized, zeroed and<br />

borderless<br />

★ margin & padding: 0<br />

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,field<br />

set,input,textarea,p,blockquote,th,td<br />

★ border: 0<br />

fieldset,img,abbr


fonts.css<br />

body {font:13px arial,helvetica,clean,sansserif;*font-size:small;*font:x-small;}<br />

table {font-size:inherit;font:100%;}<br />

select, input, textarea {font:99%<br />

arial,helvetica,clean,sans-serif;}<br />

pre, code {font:115% monospace;*font-size:<br />

100%;}body * {line-height:1.22em;}<br />

★ handles uneven font-scaling<br />

★ sets standard line-height across browsers


Using <strong>YUI</strong> <strong>CSS</strong><br />

★ Download <strong>the</strong> latest build and use from your<br />

~/css directory<br />

★ Or link to files served from Yahoo! servers:<br />

<br />

★ (a combined file; minimized and<br />

compressed served by Yahoo)<br />

★ First, include <strong>YUI</strong> css files.<br />

Ei<strong>the</strong>r download, or serve from Yahoo<br />

★ Explicitly set h1, h2, p, etc. in your own<br />

master.css


grids.css<br />

woohoo – this is <strong>the</strong> cool <strong>stuff</strong>!


page width IDs<br />

doc 750px<br />

doc2 950px<br />

doc3 100%<br />

Build Your Page: doc<br />

<br />

Header <br />

Body <br />

Footer <br />

<br />

* border colors have been applied for clarity<br />

*


Build Your Page: template<br />

<br />

Header <br />

<br />

<br />

Main <br />

<br />

Side <br />

<br />

Footer <br />

<br />

(“yui-b” = “yui block”)<br />

template classes<br />

.yui-t1 160px on left<br />

.yui-t2 180px on left<br />

.yui-t3 300px on left<br />

.yui-t4 180px on right<br />

.yui-t5 240px on right<br />

.yui-t6 300px on right<br />

.yui-t7<br />

One full-width<br />

column


.yui-t2 - 180px on left<br />

.yui-t3 - 300px on left<br />

Build Your Page:<br />

template presets<br />

.yui-t4 - 180px on right<br />

.yui-t5 - 240px on right


Build Your Page: grids<br />

★ Instant two- to four-column sections<br />

★ Safe nesting<br />

★ Source order independent<br />

<br />

<br />

<br />


Cascading Style Sheets<br />

http://flickr.com/photos/cayusa/477619516/<br />

Abstract and re-use!


Cascade for Simple Folk<br />

★Last style applied takes<br />

effect!<br />

★ Doesn’t matter if in<br />

single/multiple files.<br />

★ Set all colors in one<br />

file, fonts in ano<strong>the</strong>r<br />

file, etc.


The Cascade<br />

<br />

<br />

★ Use to override previous<br />

styles<br />

★ Create custom <strong>the</strong>mes for<br />

users, seasons, accessibility<br />

★ Separation of concerns:<br />

layout.css vs. winter.css<br />

/* master.css */<br />

.tagline {<br />

color: #ccc;<br />

}<br />

/* winter.css */<br />

.tagline {<br />

color: #aaa;<br />

}


A Sense of Style<br />

★ Use semantic names as much as<br />

possible<br />

#logo, .tagline, .thumbnail,<br />

#profile_gallery<br />

★ Keep <strong>the</strong> non-semantic names<br />

to a bare minimum if used at all<br />

.black_line, #left_whitespace<br />

★ Indentation & comments. (Can<br />

be stripped later.)


Use “standards mode”<br />

<br />

Yeah, so it takes a little more attention to detail, but...<br />

★ Trigger a more consistent<br />

HTML interpretation across<br />

browsers<br />

★ Accessibility-friendly<br />

★ Don’t be MySpace


Top 5 FAQ<br />

in under 5 minutes!


How do floats work?<br />

img.thumbnail { float: left; }<br />

★ Don’t “align” - float!<br />

★ Like a rock in a stream, o<strong>the</strong>r elements<br />

FLOAT around it.<br />

★ To make <strong>the</strong> next element CLEAR <strong>the</strong><br />

bottom of your floated item, clear it.<br />

div#gallery { clear: left; }


Float Your Cares Away<br />

Or, <strong>the</strong> benefits of using float.<br />

★ Mimic table layouts <strong>with</strong>out <strong>the</strong> table!<br />

★ Specific per-column margins & padding<br />

(Bet your tables can’t do that!)<br />

★ Progressive downloading in floated column<br />

layouts.<br />

★ For <strong>the</strong> skinny, check out Max Design’s<br />

Floatutorial.<br />

http://css.maxdesign.com.au/floatutorial/


What about positioning?<br />

position: absolute;<br />

★ “Where does this element go in relation to<br />

its PARENT?”<br />

div#absolute {<br />

/* parent is body */<br />

position: absolute;<br />

top: 40px;<br />

left: 40px;<br />

}<br />

★ Removed from regular document flow.


More positioning...<br />

position: relative;<br />

★ “Where does this element go in relation to<br />

its MARKUP?”<br />

div#relative_box {<br />

position: relative;<br />

top: 40px;<br />

left: 40px;<br />

}<br />

★ Previous place held occupied!


Mixing relative and<br />

absolute positioning<br />

★ To absolutely position something inside an<br />

element, set <strong>the</strong> wrapping element to<br />

position: relative.<br />

★ For more on positioning, peek at BarelyFitz<br />

Designs’ Learn <strong>CSS</strong> Positioning in Ten Steps.


Inline divs? Block span?<br />

★ All elements display as ei<strong>the</strong>r block or<br />

inline by default.<br />

★ They can also be forced to do <strong>the</strong> opposite!<br />

★ Give a span a height and width by adding<br />

display: block<br />

★ K.I.S.S. - Ask yourself if <strong>the</strong>re’s a better<br />

markup element to use instead!<br />

h1#subheader {<br />

display: inline;<br />

text-align: left;<br />

font: 10px Ar...<br />

}<br />

=<br />


So, what about tables?<br />

★ Leave tables for large amounts of tabular data.<br />

★ Learn a solid table-replacement <strong>CSS</strong><br />

technique.<br />

div.thumbnail {<br />

float: left;<br />

width: 100px;<br />

height: 100px;<br />

margin: 0 20px 20px 0;<br />

}<br />

!<br />

!<br />

!<br />

!


Stuff I’d Recommend :-)<br />

★ <strong>YUI</strong> <strong>CSS</strong> Cheatsheet!<br />

http://yuiblog.com/assets/pdf/cheatsheets/css.pdf<br />

★ TextMate, Transmit, <strong>CSS</strong>Edit, Coda, Free Ruler,<br />

DigitalColor Meter (OS X)<br />

★ <strong>CSS</strong>Viewer, Firebug (Firefox), Opera 9/Mini<br />

★ Dolor Sit Amet (OSX/Dashboard)<br />

★ Web Developer’s Handbook<br />

http://www.alvit.de/handbook/


Thank you!<br />

• Slides<br />

http://webchic.net/talks/yui<br />

• Yahoo Grids<br />

http://developer.yahoo.com/yui/grids/<br />

• See it in action!<br />

http://www.yellowbot.com<br />

http://www.webchic.net<br />

• More questions? Need help?<br />

vani@webchic.net

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!