Estelle Weyl | @estellevw | Github | Press to advance, 2 for comments, 4 to read/write notes.

Who are you?

How this slide deck works

Click on the #4 to show some notes stored with local storage

Press to advance and show next comments

Press to go back

Or navigation with buttons or browser history

Files are at estelle.github.com/oscon12

Schedule

  • The not so basic basics
    • Selectors
    • Specificity
    • Media Queries
  • Make a Slide Deck
    • border radius
    • shadows
    • gradients
    • transitions
    • Transforms
  • We don't have time to cover everything in depth, but resources are available to dive deeper

Specificity

Understanding Specificity

  • ID
  • Class
  • Element
  • 1-0-0
  • 0-1-0
  • 0-0-1

PDF
Examples

Specificity: The less than obvious

The * selector, or global selector, has no value.

* {} 0-0-0 

Combinators, like ~, >, and + have no value

ul li {} 0-0-2
ul > li {} 0-0-2

:not has no value, but parameter selector does

.myClass:not(p) {} 0-1-1

Specificity is not inheritance

Media Queries

media queries

<link rel='stylesheet' type='text/css' 
    media='screen' href='css/styles.css' />

<link rel='stylesheet' type='text/css' 
    media='print' href='css/print.css' />
@media screen {
  p {
    color: blue;
  }
}

@media print {
  p {
    color: red;
  }
}
  

10 Media Queries (2.1)

  1. all
  2. aural
  3. handheld
  4. braille
  5. embossed
  6. print
  7. projection
  8. screen
  9. tty
  10. tv
<link media="screen" ...
<style> @import "myCSS.css"; ...
@import url(myCSS.css) screen; IE8+
@media screen {}
<?xml-stylesheet media="screen" ...

media queries

<link rel='stylesheet' 
media='screen and (min-width: 320px) and (max-width: 480px)'
href='css/smartphone.css' />
@media screen and (max-width: 480px){
  a {
    transition: background-color 200ms linear 50ms;
  }
}

@media screen and (orientation: landscape) {
  a[href^="mailto:]:before {
    content: url(icons/email.gif);
  }
}
  
  • (min/max)-width: viewport width
  • (min/max)-height: viewport height
  • (min/max)-device-width: screen width
  • (min/max)-device-height: screen height
  • orientation: portrait(h>w) | landscape(w>h)
  • (min/max)-aspect-ratio: width/height
  • (min/max)-device-aspect-ratio: device-width/height
  • (min/max)-color:
  • (min/max)-color-index:
  • (min/max)-monochrome: 0 | 1+
  • (min/max)-resolution: 72dpi | 100dpcm
  • scan: progressive | interlace (tv)
  • grid: 0 | 1 (grids (like tty) or bitmap)
  • See Media Queries Spec

More Media Query Tidbits

media="only print and (color)"

media="only screen and (orientation: portrait)"

media="not screen and (color)"

media="print, screen and (min-width: 480px)"
@media screen and (-webkit-min-device-pixel-ratio: 2) {
 .iphone4 { /* high DPI */}
}
@screen and (transform-3d) {
  .transforms {}
}

Also works with (animation) and (transition)

Play with presentation window size

#presentation {
	-<prefix>-transition: all 1.5s linear;	
}
@media only screen and (orientation: portrait) {
	#presentation{
	  background: indianred;
	}
}
@media only screen and (max-width: 480px) {
	#presentation {
	  background: palegoldenrod;
	}
}

shrink this window to see the presentation change colors

Portrait v. Landscape

Forcing portrait mode

@media only screen and (max-device-width: 480px) and (orientation: landscape){
    #containerDiv{
       -webkit-transform:rotate(-90deg);
       -webkit-transform-origin: 160px 160px;
       }
    }

Forcing Landscape Mode

@media only screen and (max-device-width: 480px) and (orientation: portrait){
    #containerDiv{
       -webkit-transform:rotate(90deg) scale(1.45);
       -webkit-transform-origin: 230px 230px;
       }
    }

JS Orientation Detection

switch(window.orientation){
   case 0:
       //handle portrait actions
       //document.getElementsByTagName('body')[0].className = 'portrait';
       break;
  case -90:
  case 90:
       // handle landscape actions
       //document.getElementsByTagName('body')[0].className = 'landscape';
       break;
} //end switch

Event

onOrientationChange

We're going to Make a Slide Deck

Because CSS is Awesome

The deck we're making

Download the files (if you haven't already)

The HTML

<div id="presentation">
<div id="slides">
 <!-- slide -->
  <div class="slide normal"> 
    <header><h1>Slide Header</h1></header>
    <section>
      <pre contenteditable>some code</pre>
    </section>
  </div>
 </div>
</div>

<script src="prefixfree.js"></script>
<script src="slides.js"></script>

Give the slide deck breathing room

body,
#presentation {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0px; 
  top: 0px;
}

#presentation {
  overflow: hidden;
}

Center the slide on the page

.slide {
  width: 900px;
  height: 700px;
  background-color: #efefef; }

Refresh

.slide {
  position: absolute;
  left: 50%;
  top: 50%;}

Refresh

Center the slide on the page

.slide {
    margin-top: -350px;
    margin-left: -450px;
}

Refresh

sooooo ugly

add some prettiness and refresh again

.slide {
    padding: 20px;
} 
body {
    font-family: sans-serif;
}

Slide location (class set with JS)

.slide {
  display: none; 
  overflow: hidden;
}
.past, .current, .future {
  display: block;   
}
.slide.past    { margin-left: -1400px;}
.slide.current { margin-left: -450px;}
.slide.future  { margin-left: 500px;}

Refresh

The slide deck now works, but it's ugly, and the transitions suck!

You can continue with index.html, or go to index02.html

Rounded Corners

Border Properties: border-radius

.slide {
	border-radius: 50px;
}

Can we use selectors to give different slides different corners?

Rounded corners

.slide {
	border-radius: 50px 0;
}
.slide:nth-of-type(odd) {
	border-radius: 0 50px;
}

Spiffier Borders with Shadows

#presentation {
  background-color: #000;  
}

Shadows: box-shadows

.slide {
  border: 5px solid #fff;
  box-shadow: 0 0 20px rgba(0,0,0,0.6), 
              inset 0 0 6px rgba(0,0,0,0.4);
}

Box Model Gotcha!

Box Sizing

.slide {
  box-sizing: border-box;   
}

Default font sizes?

Font-size: rem units

:root { font-size: 162.5%;  }

h1    { font-size:1.8rem;   }

pre   { font-size: 1.5rem;  }
 
p     { font-size: 1.5rem;
        margin: 1rem 0 0 0; }

Boring Background?

Gradients

#presentation {
  background-image: 
    linear-gradient(#b8c6df,#6d88b7);
  background-image: 
    linear-gradient(to bottom, 
                    #b8c6df 0%,
                    #6d88b7 100%);
}

continue on in your current file, or go to index03.html

background-image: 
 linear-gradient(left, rgba(0,0,0,0.2) 50%, transparent 50%),
 linear-gradient(left, transparent 40%, rgba(0,0,0,0.2) 40%),
 linear-gradient(left, transparent 60%, rgba(0,0,0,0.2) 60%),
 linear-gradient(left, transparent 50%, rgba(0,0,0,0.2) 50%),
 linear-gradient(left, transparent 40%, rgba(0,0,0,0.2) 40%),
 linear-gradient(left, transparent 60%, rgba(0,0,0,0.2) 60%),
 linear-gradient(left, transparent 50%, rgba(0,0,0,0.2) 50%),
 linear-gradient(left, transparent 40%, rgba(0,0,0,0.2) 40%),
 linear-gradient(left, transparent 60%, rgba(0,0,0,0.2) 60%),
 linear-gradient(left,
      red 14%, 
      orange 15%, orange 28%, 
      yellow 29%, yellow 42%, 
      green 43%, green 56%, 
      blue 57%, blue 70%, 
      magenta 71%, magenta 85%, 
      purple 86%);
 background-size: 
      1px 50%, 
      1px 50px, 
      32px, 120px, 
      80px, 60px, 
      90px, 110px, 
      70px, 500px;
}

Sexier slide transitions

Transition properties

.slides {transition: 1s;}
.slide            {opacity: 0.5;}
.slide.far-past   {margin-left: -2400px;}
.slide.past       {margin-left: -1400px;}
.slide.current    {margin-left: -450px; 
                   opacity: 1;}
.slide.future     {margin-left: 500px;}
.slide.far-future {margin-left: 1500px;}
.slides {transition: margin-left 1s, 
         opacity 2s;}

continue on in your current file, or go to index04.html

Transforms

Transforms

.slide {transform: scale(0.8);
       transition: 
          margin-left 1s, 
          transform 1s,
          opacity 2s;}
.slide.current    {transform: scale(1);}
.slide {transition: all 1.2s linear;}

Check out your slide deck!