Loading...

This presentation is an HTML5 website

Press key to advance.

Having issues seeing the presentation? Read the disclaimer

Slides controls
  • and to move around.
  • Ctrl/Command and + or - to zoom in and out if slides don’t fit.
  • S to view page source.
  • T to change the theme.
  • H to toggle syntax highlight.
  • N to toggle speaker notes.
  • 3 to toggle 3D effect.
  • 0 to toggle help.

HTML5 + CSS3

was bringen die neuen Standards

Ein Gast-Vortrag von Brigitte Jellinek an der HTW Berlin, basierend auf

HTML5 ~= HTML + CSS + JS

Überblick

HTML5 Tags

ganz wenige ...

HTML5 Offline & Storage
HTML

Endlich Einfach!

XHTML

<DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
    </body>                              
</html>

HTML 5

<DOCTYPE html>
<html>
    <head>
       <meta charset="utf-8" />
    </head>
    <body>
    </body>                              
</html>         
            
HTML

Mehr Struktur

<body>
  <header>
    <hgroup>
      <h1>Page title</h1>
      <h2>Page subtitle</h2>
    </hgroup>
  </header>

  <nav>
   <ul>
     Navigation...
   </ul>
  </nav>
  <section>
   <article>
     <header>
       <h1>Title</h1>
     </header>
     <section>
       Content...
     </section>
   </article>
   <article>
     <header>
       <h1>Title</h1>
     </header>
     <section>
       Content...
     </section>
   </article>
  </section>

  <aside>
   Top links...
  </aside>

  <figure>
    <img src="..."/>
    <figcaption>Chart 1.1</figcaption>
  </figure>

  <footer>
   Copyright ©
<time datetime="2010-11-08">2010</time>. </footer> </body>
HTML

Neues für Formulare

<input type="email" value="some@email.com" />

<input type="date" min="2010-08-14" max="2011-08-14" value="2010-08-14"/>

<input type="range" min="0" max="50" value="10" />

<input type="search" results="10" placeholder="Search..." />

<input type="tel"  placeholder="+49 (0)30-5555" />

<input type="color" placeholder="e.g. #bbbbbb" />

<input type="number" step="1" min="-5" max="10" value="0" />
HTML

Neue Formular-Elemente am Handy

type="text"
android keyboard on input type text
Android Device
type="number"
android keyboard on input type number
Android Device
type="email"
iphone keyboard on input type email
iPhone Device
type="tel"
iphone keyboard on input type tel
iPhone Device
HTML

Formular-Prüfung

<input type="text" required /> <input type="email" pattern=".*@.*" title="E-Mail Adresse mit @" /> <input type="submit" />

Grafik / Multimedia

2D & 3D

HTML5 3D & Effects HTML5 Multimedia
HTML JS

Audio + Video

<audio id="audio" src="sound.mp3" controls></audio>
document.getElementById("audio").muted = false;
<video id="video" src="movie.webm" autoplay controls></video>
document.getElementById("video").play();
HTML JS

Canvas 2D

<canvas id="canvas" width="838" height="220"></canvas>

<script>
  var canvasContext = document.getElementById("canvas").getContext("2d");
  canvasContext.fillRect(250, 25, 150, 100);

  canvasContext.beginPath();
  canvasContext.arc(450, 110, 100, Math.PI * 1/2, Math.PI * 3/2);
  canvasContext.lineWidth = 15;
  canvasContext.lineCap = 'round';
  canvasContext.strokeStyle = 'rgba(255, 127, 0, 0.5)';
  canvasContext.stroke();
</script>
HTML JS

Canvas Beispiel mit Bildern

HTML JS

Canvas Beispiel Spiel

HTML JS

Canvas 3D (WebGL)

<canvas id="canvas" width="838" height="220"></canvas>

<script>
  var gl = document.getElementById("canvas").getContext("experimental-webgl");
  gl.viewport(0, 0, canvas.width, canvas.height);
  ...
</script>
            
HTML

Inline SVG

<html>
  <svg>
    <circle id="myCircle" class="important" cx="50%" cy="50%" r="100" 
        fill="url(#myGradient)"
        onmousedown="alert('hello');"/>
  </svg>
</html>
HTML

SVG example

Media Queries

und Responsive Web Design

HTML5 Styling
CSS

Media Queries

/* hier ganz viele CSS-Angaben für alle Ausgabegeräte */

@media only screen and (min-width: 768px) {

  /* hier die CSS-Angaben nur für große Bildschirme */
  .sidebar {
    width:300px;
    float:right;
  }
}

Design das verschiedene Ausgabegeräte mitdenkt: Responsive Webdesign. Siehe Artikel in A List Apart vom Mai 2010. Beispielseite auf verschiedenen Fenster-Größen betrachten!

CSS3

Presentation & Styling

HTML5 Styling
CSS

CSS Selectors

Selectors

.row:nth-child(even) {
  background: #dde;
}
.row:nth-child(odd) {
  background: white;
}
Row 1
Row 2
Row 3
Row 4

Image-like display

div {
  display: inline-block;
}

Specific attributes

input[type="text"] {
  background: #eee;
}

Negation

:not(.box) {
  color: #00c; 
}            
:not(span) {
  display: block; 
}  

More specific targetting

h2:first-child { ... }

div.text > div { ... } 
h2 + header { ... } 
CSS

Webfonts

@font-face {
  font-family: 'LeagueGothic';
  src: url(LeagueGothic.otf);
}

@font-face {
  font-family: 'Droid Sans';
  src: url(Droid_Sans.ttf);
}

header {
  font-family: 'LeagueGothic';
}
LeagueGothic font with no image replacement
CSS

Text wrapping

div {
  text-overflow: ellipsis;
}
A long cold winter delayed the blossoming of the millions of cherry, apricot, peach, and prune plum trees covering hundreds of square miles of the Valley floor. Then, unlike many years, the rains that followed were light and too early to knock the blossoms from their branches.
A long cold winter delayed the blossoming of the millions of cherry, apricot, peach, and prune plum trees covering hundreds of square miles of the Valley floor. Then, unlike many years, the rains that followed were light and too early to knock the blossoms from their branches.
A long cold winter delayed the blossoming of the millions of cherry, apricot, peach, and prune plum trees covering hundreds of square miles of the Valley floor. Then, unlike many years, the rains that followed were light and too early to knock the blossoms from their branches.

Play with the slider on this and further pages!

CSS

Browser-Spezifisches CSS

Der zukünftige Standard

coolness: 17%;

Die aktuelle Implementierung von Webkit (Safari+Chrome+...) und Mozilla (Firefox)

-webkit-coolness: 17%; 
-mozilla-coolness: 17%;          

Der Ausweg: CSS Präprozessor wie z.B. Less oder SASS

Warnhinweis: coolness ist nicht wirklich teil von HTML5

CSS

Columns

-webkit-column-count: 2; 
-webkit-column-rule: 1px solid #bbb;
-webkit-column-gap: 2em;

In March 1936, an unusual confluence of forces occurred in Santa Clara County.

A long cold winter delayed the blossoming of the millions of cherry, apricot, peach, and prune plum trees covering hundreds of square miles of the Valley floor. Then, unlike many years, the rains that followed were light and too early to knock the blossoms from their branches.

Instead, by the billions, they all burst open at once. Seemingly overnight, the ocean of green that was the Valley turned into a low, soft, dizzyingly perfumed cloud of pink and white. Uncounted bees and yellow jackets, newly born, raced out of their hives and holes, overwhelmed by this impossible banquet.

Then came the wind.

It roared off the Pacific Ocean, through the nearly uninhabited passes of the Santa Cruz Mountains and then, flattening out, poured down into the great alluvial plains of the Valley. A tidal bore of warm air, it tore along the columns of trees, ripped the blossoms apart and carried them off in a fluttering flood of petals like foam rolling up a beach.

This perfumed blizzard hit Stevens Creek Boulevard, a two-lane road with a streetcar line down its center, that was the main road in the West Valley. It froze traffic, as drivers found themselves lost in a soft, muted whiteout. Only the streetcar, its path predetermined, passed on...

CSS

Text stroke

div {
  -webkit-text-fill-color: black;
  -webkit-text-stroke-color: red;
  -webkit-text-stroke-width: 0.00px; 
}
Text stroke example
CSS

Opacity

  color: rgba(255, 0, 0, 0.75); 
  background: rgba(0, 0, 255, 0.75); 
Independent opacity
CSS

Hue/saturation/luminance color

color: hsla(
  128 
  74% 
  33% 
  1.00 
        
HSL example
CSS

Rounded corners

              face: border-radius: 0px; 
              left eye: border-radius: 0px; 
              right eye: border-radius: 0px; 
              base white: border-radius: 0px; 
              mouth: border-radius: 0px; 
              nose: border-radius: 0px; 
              left black eye: border-radius: 0px; 
              right black eye: border-radius: 0px; 
            
CSS

Gradients

background-image: linear-gradient(top, #00abeb 0%, #fff 50%,
                            #66cc00 50%, #fff 100%);

background-image: radial-gradient(center, circle cover, red, #000 40%);
                                                        
CSS

Shadows

text-shadow: 
  rgba(64, 64, 64, 0.5) 
  0px 
  0px 
  0px; 

box-shadow: rgba(0, 0, 128, 0.25) 0px 0px 0px;
Shadows example
CSS

Background enhancements

Background sizing

#logo {
  background: url(logo.gif) center center no-repeat;
  background-size: 
    ;
}

Resize me! »

Multiple backgrounds

div {
  background: url(src/zippy-plus.png) 10px center no-repeat, 
              url(src/gray_lines_bg.png) 0 center repeat-x;
}
            
Test
CSS

Border image

Border image No.1
Border image No.2
Border image No.3
Border image No.4
Border image No.5
-webkit-border-image: url(border_image_1.png) ; border-width: 10px;
CSS

Transitions

#box.left {
  margin-left: 0;
}
#box.right {
  margin-left: 1000px;
}

document.getElementById('box').className = 'left'; 
document.getElementById('box').className = 'right'; 
#box {
  -webkit-transition: margin-left 1s ease-in-out;
}

document.getElementById('box').className = 'left'; 
document.getElementById('box').className = 'right'; 
CSS

Transforms

Hover over me:

-webkit-transform: rotateY(45deg);
-webkit-transform: scaleX(25deg);
-webkit-transform: translate3d(0, 0, 90deg);
-webkit-transform: perspective(500px)
#threed-example {
  -webkit-transform: rotateZ(5deg);

  -webkit-transition: -webkit-transform 2s ease-in-out;
}
#threed-example:hover {
  -webkit-transform: rotateZ(-5deg);
}

Now press 3!

CSS

Animations

@-webkit-keyframes pulse {
 from {
   opacity: 0.0;
   font-size: 100%;
 }
 to {
   opacity: 1.0;
   font-size: 200%;
 }
}

div {
  -webkit-animation-name: pulse;
  -webkit-animation-duration: 2s;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-timing-function: ease-in-out;
  -webkit-animation-direction: alternate;
}

*Please make a better use of it. We don't want a new blink tag ;)

Pulse!

Offline

nicht nur fürs Handy

HTML5 Offline & Storage
HTML

Application Cache

<html manifest="cache.appcache">
cache.appcache:
CACHE MANIFEST
# version 1.0.0

CACHE:
/html5/src/logic.js
/html5/src/style.css
/html5/src/background.png

NETWORK:
*

Auch ohne Internet-Verbindung bleiben diese Dokumente zugänglich!

JS

Application Cache neu laden

<html manifest="cache.appcache">
window.applicationCache.addEventListener('updateready', function(e) {
  if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
    window.applicationCache.swapCache();
    if (confirm('A new version of this site is available. Load it?')) {
      window.location.reload();
    }
  }
}, false);
cache.appcache:
CACHE MANIFEST
# version 1.0.0

CACHE:
/html5/src/logic.js
/html5/src/style.css
/html5/src/background.png

NETWORK:
*

Auch ohne Internet-Verbindung bleiben diese Dokumente zugänglich!

JS

Local Storage

// use localStorage for persistent storage
// use sessionStorage for per tab storage
saveButton.addEventListener('click', function () {
  window.localStorage.setItem('value', area.value);
  window.localStorage.setItem('timestamp', (new Date()).getTime());
}, false);
textarea.value = window.localStorage.getItem('value');

Save text value on the client side (crash-safe)

Realtime

Stay connected

HTML5 Realtime & Communication
JS

Web Workers

Parallel-Verarbeitung in Javascript. Anspruchsvolle Berechnung an Worker auslagern.

Loading Route...

Try dragging the map while the complex route is being calculated (you will only be able to do that with Workers!)

JS

WebSocket

var socket = new WebSocket('ws://html5rocks.websocket.org/echo');
socket.onopen = function(event) {
  socket.send('Hello, WebSocket');
};
socket.onmessage = function(event) { alert(event.data); }
socket.onclose = function(event) { alert('closed'); }

Full-duplex, bi-directional communication over the Web: Both the server and client can send data at any time, or even at the same time. Only the data itself is sent, without the overhead of HTTP headers, dramatically reducing bandwidth.

Multi-User Browsergame word squared. Neu gesetzt Steine in meinem Blickfeld werden sofort an meinen Browser geschickt.

Drag-and-Drop mit Dateien

Integration mit dem Betriebssystem

HTML5 Device Access
JS

Desktop Drag-In (File API)

Vorher: Eingabefeld für Dateien

<input type="file">

Nachher: Drag-and-Drop

document.querySelector('#dropzone').addEventListener('drop', function(e) {
  var reader = new FileReader();
  reader.onload = function(evt) {
    document.querySelector('img').src = evt.target.result;
  };

  reader.readAsDataURL(e.dataTransfer.files[0]);
}, false);
Drop in images from your desktop
JS

Desktop Drag-Out

Dateien vom Browser auf den Desktop ziehen:

<a href="src/star.mp3" draggable="true" class="dragout"
   data-downloadurl="MIMETYPE:FILENAME:ABSOLUTE_URI_TO_FILE">download</a>
var files = document.querySelectorAll('.dragout');
for (var i = 0, file; file = files[i]; ++i) {
  file.addEventListener('dragstart', function(e) {
    e.dataTransfer.setData('DownloadURL', this.dataset.downloadurl);
  }, false);
}
Drag each of these files onto your desktop: .pdf file .mp3 file

( this feature is only available in Google Chrome )

Geolokation

Wo bin ich?

HTML5 Device Access
JS

Geolocation

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    var latLng = new google.maps.LatLng(
        position.coords.latitude, position.coords.longitude);
    var marker = new google.maps.Marker({position: latLng, map: map});
    map.setCenter(latLng);
  }, errorHandler);
}
HTML

Sprach-Eingabe

<input type="text" x-webkit-speech />

Nur in Chrome, verwendet eine Google-API zur Verarbeitung des Audio.

Speech input is not enabled in your browser.
Try running Google Chrome with the --enable-speech-input flag.

Leichter Javascript Programmieren

Ein paar Tricks von jQuery

HTML5 Performance & Integration
JS

Elemente im DOM finden

mit Id oder Tag Name (seit 2000)

var el = document.getElementById('section1');
el.focus();

var els = document.getElementsByTagName('div');
els[0].focus();

mit Klassen (neu in HTML5)

var els = document.getElementsByClassName('section');
els[0].focus();

mit beliebigem CSS Selektor (neu in HTML5)

var els = document.querySelectorAll("ul li:nth-child(odd)");
var tds = document.querySelectorAll("table.test > tr > td");
var el = document.querySelector("table.test > tr > td"); // el == tds[0]
JS

Klassen manipulieren

Vorher:

<div id="main" class="shadow rounded"></div>

Manipulation:

var el = document.querySelector('#main').classList;
el.add('highlight');
el.remove('shadow');
el.toggle('highlight');

console.log(el.contains('highlight')); // false
console.log(el.contains('shadow')); // false
console.log(el.classList.toString() == el.className); // true

Nachher:

<div id="main" class="rounded"></div>
JS

History API

Problem: komplexe Web-Applikation, in Javascript geschreiben, Navigation innerhalb der App verändert die URL nicht. Zurück-Knopf des Browsers funktioniert nicht wie erwartet.

link.addEventListener('click', function(event) {
  // manually add a value to the history stack
  // without making the browser load any new page
  history.pushState('Contact Page Form', 'Contact Page', '/contact');
});

// capture navigation in case we want to change,
// for instance, some content when it changes
window.addEventListener('popstate', function(event) {
  document.querySelector('h1').innerText = event.state; // 'Contact Page Form'
});
HTML CSS JS

Was geht?

HTML5 ~= HTML + CSS + JS

HTML5 = Next Generation Features for Modern Web Development

Ein Gast-Vortrag von Brigitte Jellinek an der HTW Berlin, basierend auf