CSS

Week 4

CDGD304 - Fall 2011
http://bit.ly/massart-web304-4

Order of Business

  1. Review Homework

  2. CSS in Depth

  3. CSS Layout Basics

  4. CSS Styling

  5. Exercises

Homework Review

Let's Talk CSS

Cascading Style Sheets

What is a style?

Pay attention to your class and id names!

  • You can't use spaces.

  • You shouldn't use underscores (_) - altough technically now permitted

  • Use camelCase or dashes-to-separate-names

  • I'd recommend dashes - css uses Dashses (background-color, font-family),
    Javascript uses camelCase

  • Be consistent! - easier to read and remember what you wrote.

  • Available selectors

    Selectors

    Selector combinations

    Selector Combination Exercise

    Properties

    Values

    Style Properties

    Style Properties

    Layout Properties

    Layout = Box Model



    Understanding floats + Positioning

    http://www.barelyfitz.com/screencast/html-training/css/positioning/

    Positioning 101

    Exercise: we want this

    Positioning Exercise

    Cascading - What Color?

    Cascading Hierarchy

    1. Inline style (those defined directly with a style='....' attribute in the tag)

    2. Number of ID selectors

    3. Number of Class selectors

    4. Number of tag selectors

    5. Order of appearance last to first

    6. Style inheritance

    Organizing Your CSS

    1. Start with your reset (see next slide)

    2. Set your body

    3. Set your base element styles (p, h1, h2, blockqoute)

    4. Set your reusable class styles

    5. Set your layout styles

    6. Set your module styles (additional sub-themes like blogs,custom pages, etc )

    Techniques

    Start with
    your reset

    Eric Meyer Reset
    http://meyerweb.com/eric/tools/css/reset/

    http://bit.ly/meyerreset

    Centering Content

    Give it a width and set margin: 0 auto;

    section#content {
      margin:0 auto;
      width:960px;
    }
    	

    Nitty Gritty

    Logo Replacement

    Exercise: navbar

    Navbar: Make this

    Basic Chop 101

    CSS Code

    body { width:960px; margin:0 auto; }
    		
    header#site-header {
      position:relative; height:80px;
    }
    
    #site-header h1 a { 
      display:block;	
      text-indent:-9999px;    
      position:absolute;
      width:300px; height:80px;
      background:url(logo.png) no-repeat left top;
    }
    nav#top-nav { position:absolute; right:0px; top:0px; }
    
    nav#main-menu { height:30px; background-color:black; }
    nav#main-menu ul li { display:block; float:left; padding:0 5px; }
    nav#main-menu ul li a { display:block; color:white; padding:5px 5px; background-color:blue; }
    
    section#page-content { float:left; width:550px; padding:50px 20px; }
    aside#sidebar { float:right; width:220px; padding:50px 10px;; }
    
    footer#site-footer { 
   clear:both; background-color:black; 
   color:white; padding:10px 0px; 
}

    In Class Exercise 1

    Default paragraphs to two paragraphs, with floated images




    End Result




    Floats, Clears and Clearfix

    Clearfix

    .clearfix:after {
      content: ".";
      display: block;
      clear: both;
      visibility: hidden;
      line-height: 0;
      height: 0;
    	}
    
    .clearfix { display: inline-block; }
      html[xmlns] .clearfix { display: block; }
      * html .clearfix { height: 1%; }

    Homework

    Reading

    Coding