Index

This is CSS

Cascading Style Sheets

The adjectives of the webpage. The skin.

The General rule

    
        selector {
          attribute: value;
          otherAttribute: value;
        }
    
  

Injecting CSS into HTML

  1. Inline Style

  2. Style Tag

  3. Link Tag

Selectors

Specificity

  1. Inline Styles
  2. IDs
  3. Classes, attributes and pseudo-classes
  4. Elements and pseudo-elements

Inline IDs Classes Elements
0 0 0 0

The Box Model

In a document, each element is represented as a rectangular box.

In CSS each of these boxes is described using the standard Box Model.

Each box has four edges:

Margin
Border
Padding
Element

Floats

Interrupts the normal document flow and stacks things horizontally instead of vertically

Without Float

Full width of the parent element

Normal Vertical Flow

Normal Vertical Flow

With Float

Width of the content

Added float for Horizontal Flow

Added float for Horizontal Flow

Clearfix hack after a float:

    
        <div class="cf"></div>
    
  
    
        .cf:before,
        .cf:after {
            content: " "; /* 1 */
            display: table; /* 2 */
        }
        
        .cf:after {
            clear: both;
        }
    
  

Units

Many units for different use-cases. Not all atribbutes accept the same kind of units

Colors in CSS