סדרת מפגשי לימוד
HTML5



Nir Geier - ניר גייר

מי אני ???

Is it HTML5/CSS??

Other options:

http://tjrus.com/iphone
http://disneydigitalbooks.go.com/tron/

Is it HTML5/CSS??




Is it HTML5/CSS??


Is it HTML5/CSS??


Is it HTML5/CSS??


    

Is it HTML5/CSS??


Is it HTML5/CSS??


Is it HTML5/CSS??

All the previous demos are pure HTML/JS/CSS
And this is what we are going to learn today.

What we're going to do today?

Theory

  1. Introduction
  2. Selectors
  3. Media queries
  4. Fonts
  5. Colors
  6. Border Radius
  7. Shadows
  8. Backgrounds

Hands on

Introduction

What is CSS

CSS = Cascading Style Sheets.
Syntax we are using to describe the look and formatting of a website to the browser.

Unlike CSS 2, which is a large single specification defining various features,
CSS 3 is divided into several separate documents called modules.
Each module adds new capabilities or extends features defined in CSS 2, over preserving backward compatibility.
Work on CSS level 3 started around the time of publication of the original CSS 2 recommendation.
The earliest CSS 3 drafts were published in June 1999

Selectors

Attribute selectors

selectors are patterns used to select the element(s) you want to style

Structural Pseudo-classes

Other Selectors

UI Element - Pseudo-classes

Selectors (Sample)

tr:nth-child(even) {background: #CCC}
tr:nth-child( 2n ) {background: #CCC}

tr:nth-child(odd ) {background: #FFF}
tr:nth-child(2n+1) {background: #FFF}


Header1 Header2
Cell1 Cell2
Cell1 Cell2
Cell1 Cell2
Cell1 Cell2
Cell1 Cell2
http://css-tricks.com/useful-nth-child-recipies/

Selectors (Sample)

 Check /Un-check me

.selectorsDemo+span {
    color: red;
    display: none;
    }

.selectorsDemo:checked+span {
    color: green;
    display: inline-block;
}
    

Media queries

Media queries (CSS2)

HTML4 and CSS2 currently support media-dependent style sheets tailored for different media types.

There are 10 types of media types.
The most common are:

For example, a document may use different fonts and colors when displayed on a screen and for printed.
<link rel="stylesheet" type="text/css" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" media="print" href="print.css">

Media queries (CSS3/ Responsive Design)

Media queries extend the functionality of media types by allowing more precise labeling of style sheets.

Media queries allow us to change our layouts to suit the exact need of different devices
without changing the content to a specific range of output devices and screen sizes.

Among the media features that can be used in media queries are ‘width’, ‘height’, and ‘color’.

Media queries (Syntax)

Media type is a combination of type and expression.
<link rel="stylesheet" type="text/css" media=" screen and (width) ">

An expression is combination of zero or more media features (width, height, color ...).

Media query expression return true or false

The css will be applied if the expression is true

Media features are enclosed within braces.

For example if we have css for desktop and for iphone:
<link rel=... media="all and (min-width: 480px and max-width:640px)">
<link rel=... media="all and (min-width: 640px)">

http://mediaqueri.es

Fonts
(Web typography)

Fonts (@font-face)

Fonts (Code)

@font-face{
    font-family:'HPSimplified';
    font-weight:normal;
    font-style:normal;
    src:url(http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-regular-eot.eot);
    src:url(http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-regular-eot.eot?#iefix)
    format('embedded-opentype'),
    url('http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-regular-woff.woff') format('woff'),
    url('http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-regular-ttf.ttf') format('truetype');
}

@font-face{
    font-family:'HPSimplified';
    font-weight:bold;
    font-style:normal;
    src:url(http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-bold-eot.eot);
    src:url(http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-bold-eot.eot?#iefix)
    format('embedded-opentype'),
    url('http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-bold-woff.woff') format('woff'),
    url('http://www8.hp.com/h10180/hp-fonts/v2-0/hps-euro-w01-bold-ttf.ttf') format('truetype');
}
        

Fonts (Resources)

A web-font for creating multi-layered weather icons
Setting Weights And Styles With The @font-face Declaration

Colors

Colors

There are several ways to define colors:

Colors - opacity

There are several ways to define colors:

Colors - HSL

HSLhsl(200,10%,50%)

hsl(200,10%,50%) The first value is for Hue and must be a integer value between 0 and 359.

hsl(200,10%,50%) The second value is for Saturation and must be defined as a percentage value.

hsl(200,10%, 50%) The third value is Lightness and must also be defined as a percentage value.

Colors

Why use HSL or HSLA?

  1. Because you can
  2. Mostly used by designers and not programmers

How do we spell the keyword gray/grey?

CSs3 keywords include gray, grey, darkgrey and darkgray.

Browsers Axis

CSS Box

There are 3 boxes:

CSS Box (Syntax)

The box is defined using 4 values in the following order:

CSS Box

CSS Box (Syntax)

If one of the values is missing it will be filled in the following way:

Border Radius

Border Radius

The CSS3 border-radius property allows you to easily apply rounder corners to elements without using images.

Border Radius

There are few ways to define border radius.

If all four corners have the same radius, you can use the shorthand border-radius property with a single value.
border-radius:10px; -> border-radius:10px 10px 10px 10px;

Border Radius (samples)

Border Radius

border-radius:50% 50% 50% 50%/60% 60% 40% 40%;
http://www.bchanx.com/logos-in-pure-css-demo
Excellent lecture about many aspects of Border radius by Lea Verou
The humble border-radius - Lea Verou - Front-Trends 2013

Border Radius

Where should we use it?

Hp Logo


Shadows

Shadows - Text Shadows

The CSS3 text-shadow property allows you to apply one or more shadows to any block of text.

The property takes 3 lengths values and a color value.

text-shadow: +/- x Offset +/- y Offset Blur Color
Text-shadow must include the two offset values. Blur radius and a shadow color are optional.
The higher the blur radius number, the softer the text-shadow will be.

Shadows - Text Shadows



Shadows - Text Shadows



Shadows - Text Shadows



Shadows - Box Shadows

Shadows - Box Shadows

The CSS3 box-shadow property allows you to apply one or more shadows to any box.

You can define outer and inner box shadows.

The property allows 4 length values, a color value and an optional “inset” keyword.

text-shadow: +/- x Offset +/- y Offset Blur Spread Color
Spread:
Positive values cause the shadow to expand in all directions (so the shadow appears larger than the box).
Negative values cause the shadow to contract in all directions (so the shadow appears smaller than the box).

Shadows - Box Shadows & border radius

The box-shadow should follow any curved corners that have been defined with border-radius.

http://studentwebhosting.com/media/demos/css-box-shadow

Backgrounds

Backgrounds

CSS2 five background-properties:

Backgrounds (background-position)

CSS2 syntax: background-position: 10px 10px;

CSS3 syntax: background-position: left 10px top 15px;

Backgrounds (background-repeat)

In CSS2.1, we could change the repeat behaviour using four different keywords.

In CSS3, we can now define background-repeat using two values instead of one.
background-repeat: repeat repeat;
Backward compatibility: background-repeat: repeat [repeat];

CSS3 also allows us to use two new values with the background-repeat property:
space
round

Backgrounds (background-repeat [space])

The space value sets the image to repeat as often as will fit within the background area and then
the images are spaced out to fill the area.
The first and last images touch the edges of the area.

Backgrounds (background-repeat [round])

The round value sets the image to repeat as often as will fit within the background area.
If it doesn't fit a whole number of times, it is rescaled so that it does.
Be aware that the background images may be stretched or distorted using this method.

Backgrounds

CSS3 offers three entirely new background properties:

Backgrounds (background-origin)

The background-origin property is used to determine where background images are positioned inside a box.

The background-clip property is used to determine where and if background images are clipped (or cut off) inside the background area.


Backgrounds (background-size)

The background-size property allows us to set the size of our background images.
background-size: 10px 20px;
We can set the size using length values, percentage values or one of two new keywords:
contain, cover

Backgrounds (Multiple backgrounds)

With CSS2.1, we could only add one background image to any HTML element.

CSS3 allows us to add multiple background images to any element!

http://lea.verou.me/css3patterns/

Whats have we missed?