<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Programmation Web Avancée Client-Side Basics</title>
<meta name="cours-n" content="2">
<meta name="author" content="Rémi Emonet">
<meta name="venue" content="PWA M1 DSC">
<meta name="date" content="2016">
<meta name="affiliation" content="Université Jean Monnet − Laboratoire Hubert Curien">
<style type="text/css">
</style>
<style type="text/css">
.TIB {font-family: arial; font-size: 20px; border: 1px solid black; margin-top: -20px; padding: 10px; overflow:auto;}
.TIB img.float {transition: all 500ms; float: right;}
.TIB.styly {font-size: 30px; font-family: "Palatino Linotype", Palatino, Palladio, "URW Palladio L", "Book Antiqua", Baskerville, "Bookman Old Style", "Bitstream Charter", "Nimbus Roman No9 L", Garamond, "Apple Garamond", "ITC Garamond Narrow", "New Century Schoolbook", "Century Schoolbook", "Century Schoolbook L", Georgia, serif; }
.TIB ol.roman {list-style-type: upper-roman !important;}
.TIB img.border {border: 5px solid red;}
.TIB img.border {border: 5px solid red; }
.TIB img.border.shadow {transition: all 700ms; box-shadow: -10px 10px 10px black;}
.TIB input:hover {transition: all 700ms; box-shadow: 0px 0px 10px blue;}
.TIB li.blue {color: blue; }
.TIB li.green {color: green; font-weight: bold; }
.TIB img.bordered {border: 50px solid blue;}
li.server em {color: grey;}
.listisalpha ol {list-style: lower-alpha;}
.PAGE { font-family: helvetica; font-size: 16px; border: 1px solid grey; margin: 10px; box-shadow: 2px 2px 3px black;}
.selectors li em {font-weight: bold; font-family: monospace; display: inline-block; min-width: 40%;}
.selectors li em::after {content: ' ⇒ '; color: grey;}
section blockquote { font-size: 22px;}
.withredborder { border: 5px solid red; }
.withpinkoutline { outline: 5px solid pink; }
</style>
<!--
<script src="deck.js/extensions/includedeck/load.js"></script>
<script src="extensions/slides-dev.js"></script>
-->
<script src="extensions/deck-packed.js"></script>
<script src="extensions/slides.js"></script>
<script>go()</script>
</head>
<body>
<div class="deck-container">
<div class="deck-loading-splash" style="background: black; color: chartreuse;"><span class="vcenter" style="font-size: 30px; font-family: Arial; ">Please wait, while our marmots are preparing the hot chocolate…</span></div>
<section class="smart">
# @chunk: chunks/title.md
# Questions? <br/> Comments? {no-print}
# @chunk: chunks/objectives.md
## Design of Web Applications <span>{var-cours-n}</span> : Overview {#plan overview}
- Introduction {intro}
- HTML and DOM {dom}
- Styling and CSS {styling}
- More {more}
# @copy:#plan
# @copy:#plan: %+class:inred: .intro
## Client Side Technologies {/no-status} // hum
- A few langages {dense}
- HTML (declarative langage): page structure {html}
- CSS (declarative langage) : styling of elements {css} // including le hover sur les widgets
- Javascript (imperative/functional langage) : behavior {js} // le form dont avec le bouton + click l'image
- *Java, PHP, Python, ... : server-side behavior* {server} // also js
- @anim: .html + .TIB | .TIB p.par | .TIB img | .TIB ol | .TIB form | .TIB p.links | .css
- @anim: %+class:float:.TIB img
- @anim: %+class:styly:.TIB
- @anim: %+class:roman:.TIB ol
- @anim: %+class:border:.TIB img
- @anim: %+class:shadow:.TIB img
- @anim: %+class:green:.TIB li
- @anim: .js | .server
<div class="TIB">
<p class="par">This is a paragraph with an image, followed by a list and a form and two links. All together, they form a web page.</p>
<img src="media/kitten.jpg" width="200px" onclick="$(this).toggleClass('bordered')">
<ol>
<li>first interesting element</li>
<li>second element</li>
</ol>
<form>
<input type="text" id="tibtext" placeholder="your name..."><input type="submit" value="go" onclick="alert('Hey '+document.getElementById('tibtext').value+'! What\'s up?!')">
</form>
<p class="links">
<a href="http://graphhopper.com/" target="_blank">to infinity</a>
and <a href="https://cozy.io/" target="_blank">beyond</a>
</p>
</div>
# @copy:#plan: %+class:inred: .dom
## A Simple HTML page (minimal) {libyli}
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
</head>
<body>
content
</body>
</html>
{slide dense}
```
- HTML Page Structure
- `html` root element
- `head` for metadata (encoding, title, ...)
- `body` for the actual page content
- HTML Elements {libyli}
- head elements: meta, title, style, script
- body elements: p, h1, h2, …, h6, ul, ol, li, dl, form, input, table, …
- more body elements: a, em, strong, i, b, …
- more body elements: div, span, img, video, object, …
## The Document Object Model (DOM) {libyli}
<blockquote>
<img class="floatright c5" src="media/dom-tree.png" alt="dom tree"/>
<p>
a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML, and XML documents
</p>
</blockquote>
- A set of nodes
- representing the document
- organized in a tree structure
- navigable in any direction (parent, children, previous/next siblings)
- A representation of an HTML document
- tree of elements
- each with possible attributes
- With APIs
- to manipulate the tree
- available for most existing languages
- (most importantly in this course, Javascript)
## Basic HTML Elements {libyli}
```html
<h3>Demo</h3>
<p class="hummm yeah">
This is a paragraph with an image then a list
and a form and two links
</p>
<img src="media/kitten.jpg" width="200px" alt="kitten">
<ol>
<li>first interesting element</li>
<li>second element</li>
</ol>
<form>
<input type="text" id="datext" placeholder="name...">
<input type="submit" value="go">
</form>
<p class="links">
<a href="http://graphhopper.com/">to infinity</a>
and <a href="https://cozy.io/">beyond</a>
</p>
{}
```
- Headings (`h1`...`h6`), paragraphs (`p`),
ordered (numbered) and un-ordered lists (`ol`, `ul`), list items (`li`),
images (`img`), links (`a`) {dense}
- <a href="http://dev.w3.org/html5/spec-author-view/Overview.html#contents">More</a>: section, nav, article, code, sup, sub, blockquote, pre, table/tr/td, … {dense}
- un-semantic blocks element (`div`) and inline element (`span`) {dense}
# HTML: Questions? Demo?
# @copy:#plan: %+class:inred: .styling
# CSS <br/> never go out of style
## Making the Web, With Style
<div class="PAGE">
<p>This is a first paragraph.</p>
<p style="color: red;
border: 1px solid blue;
background: #EEF;
margin-left: 50px;
padding-bottom: 30px;
">This is a second paragraph.</p>
</div>
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
</head>
<body>
<p>This is a first paragraph.</p>
<p style="
color: red; border: 1px solid blue; background: #EFF;
margin-left: 50px; padding-bottom: 30px; ">
This is a second paragraph.
</p>
</body>
</html>
{slide dense}
```
- Style declarations {slide}
- «property» `:` «value»
- declarations are semicolon-separated (`;`)
## Basics of Cascading Style Sheets (CSS) {libyli}
- Motivation
- separate content from styling
- Principle
- define styling rules to apply to elements
- e.g., all paragraphs should have a margin
- CSS Syntax {libyli}
- comments: `/*` «whatever» `*/`
- NB: * // ...{smartcode}* is not a comment in CSS
- rule: «selector» `{{}` «semi-colon-separated-declarations» `}{}`
- example: `p.cool {color: red;}{}`
- Where to put the CSS rules?
- directly in a `style` element (within the `head`)
- in a separate file, with a `.css` extension, <br/> included with a `link rel="stylesheet"` element
## Basic CSS Selectors <a href="http://www.w3.org/TR/selectors/" target="_blank">…</a> {libyli}
- Element selector
- `*`: any element (any node in the tree)
- `e`: any element of type `e` (any node *<e>{smartcode}*)
- Class selector
- `.c`: any element with class `c` (e.g. *<p class="toto c z">{smartcode}*)
- Identifier selector
- `#toto`: any element with identifier `toto` (e.g. *<p id="toto">{smartcode}*)
- Conjunctions of selectors (no spaces) and “or”
- `e.c`: any element of type `e` with class `c`
- `e.c.d`: any element of type `e` with both class `c` and `d`
- `e#i`: element of type `e` if it has id `i`
- `E, F`: any element matching `E` or `F`
- Children and descendants
- `E F`: any `F` that is a **descendant** of a `E`
- *E > F{smartcode}* (or *E>F{smartcode}*): any `F` that is a **child** of a `E`
## More Advanced CSS Selectors {libyli}
- Attribute filters
- `E[attt]`: any `E` with a `attt` attribute
- `E[attt="toto"]`: any `E` with a `attt` attribute equal to `toto`
- `E[attt*="toto"]`: any `E` with a `attt` attribute contains `toto`
- …
- Pseudo-classes
- `:visited`: any already visited link
- `:hover`: an element with the mouse hovering it
- Following siblings
- `E + F`: any `F` that **immediately** follows an `E`
- `E ~ F`: any `F` that follows an `E`
# CSS Styling: Questions? Demo?
# CSS Styling: Box Model − Live
## CSS Styling: Box Model {libyli}
@SVG:media/border4.svg 200px 200px {floatright defaults}
<div class="demo floatright" style="clear: both; font-size: 70%; border: 1px dotted black;"><div>The <span class="demospan" style="display:inline-block; color: darkred">box</span> model</div></div>
- Margin
- example: `margin: 1em 2em 3em 4em`
- @anim: .defaults
- space around the object
- @anim: %attr:.demospan: margin: .5em 1em 1.5em 2em
- Border
- example: `border: 5px solid red`
- @anim: %%class:withredborder:.demospan
- Padding
- example: `padding: 1em 2em 3em 4em`
- space inside the object's border
- @anim: %attr:.demospan: padding: 0.5em 1em 1.5em 2em
- Outline (mostly for debugging)
- like a border, but takes no space
- @anim: %%class:withpinkoutline:.demospan
- Defaults, shorcuts and units {libyli}
- can use less than 4 values
- @anim: #a2to1,#a3to1,#a4to2
- can set only a part, e.g., `margin-left: 0`, `padding-right: 0`
- @anim: %attr:.demospan: margin-left: 0 +
- @anim: %attr:.demospan: padding-right: 0
- possible units: `0` (with no unit), `px`, `pt`, `em`, `%`
# CSS Styling: Positioning − Live
## CSS Styling: Positioning
- Notion of `display` as `inline`, `inline-block`, `block`
- Positioning (`left`, `top`, ..., `height`)
- `static`: default preferred positioning
- `relative`: offset with the preferred position
- `fixed`: absolute position inside the page
- `absolute`: position in the reference frame of the closest positioned ancestor
- Box sizing:
- `box-sizing: content-box` (default)
- `box-sizing: border-box`
- Flexbox !
# CSS Styling: Transitions/Animations − Live
## Priorities and Specificity in CSS {libyli}
- Priorities (decreasing)
- `!important`-values <br/>> inline-style <br/> > (CSS RULES) selector-specificity <br/> > (CSS RULES) rule-order <br/> > parent-inheritance <br/> > browser-default
- Selector specificity (<a href="http://specificity.keegan.st/" target="_blank">try</a>) {selectors}
- *p {color: white;}* 1
- *p em {color: green;}* 2
- *div p em {color: green;}* 3
- *.fancy {color: red;}* 1,0
- *p.fancy {color: blue;}* 1,1
- *p.fancy em.cool {color: yellow;}* 2,2
- *#id218 {color: brown;}* 1,0,0
- *(inline) style="…"* 1,0,0,0
## Different Ways of Adding Style {libyli}
1. Inline, with style attribute
- priority over other solutions
- thus, difficult to override
- *recommendation*: do not use it
2. Using CSS rules (preferred way) {listisalpha}
1. in a `style` element
2. in a file included via a `link rel="stylesheet"` element
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="allblue.css">
<style> p {color: red;} </style>
</head>
<body>
<p style="color: green">This is a paragraph.</p>
</body>
</html>
{slide dense}
```
# @copy:#plan: %+class:inred: .more
## Potentially Useful Tools for Experimentation
- Your favorite editor + a browser + F5 (or an auto-refresh)
- Your browsers "dev tools" (Ctrl+Shift+I)
- A live CSS editor with autocompletion, in your browser, like <a href="http://liveweave.com/" target="_blank">liveweave</a>
- A CSS-aware IDE for auto-completion
- An IDE with live CSS edition (e.g. <a href="https://netbeans.org/kb/docs/webclient/html5-editing-css.html" target="_blank">in netbeans</a>)
## Next
- HTML+CSS+… + practice
- <a href="http://learn.heeere.com/DSC/guide.html#installation">Installation</a> help-desk
## Key Points {key deck-status-fake-end}
- ?
</section>
<!-- deck.status snippet -->
<p class="deck-status deck-progress-10"> <span class="deck-status-current"></span> / <span class="deck-status-total"></span> − <span class="var-author">will be replaced by the author</span> − <span class="var-title">will be replaced by the title</span></p>
<a data-progress-size=": spe.top(15, 555); height: 45*designRatio; left: slide.right - 90*designRatio; width: 90*designRatio" class="ccby" href="http://en.wikipedia.org/wiki/Creative_Commons_license" title="This work is under CC-BY licence." target="_blank"></a>
<a class="ujm" data-progress-size=": spe.top(15, 525); height: 65*designRatio; left: slide.left; width: 130*designRatio" target="_blank"></a>
</div>
<!-- clicky Cla -->
<script type="text/javascript">
var clicky_site_ids = clicky_site_ids || [];
clicky_site_ids.push(100779706);
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//static.getclicky.com/js';
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
})();
</script>
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/100779706ns.gif" /></p></noscript>
<!-- Histats.com START (aync)-->
<script type="text/javascript">var _Hasync= _Hasync|| [];
_Hasync.push(['Histats.start', '1,2767123,4,0,0,0,00010000']);
_Hasync.push(['Histats.fasi', '1']);
_Hasync.push(['Histats.track_hits', '']);
(function() {
var hs = document.createElement('script'); hs.type = 'text/javascript'; hs.async = true;
hs.src = ('http://s10.histats.com/js15_as.js');
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hs);
})();</script>
<noscript><a href="http://www.histats.com" target="_blank"><img src="http://sstatic1.histats.com/0.gif?2767123&101" alt="javascript hit counter" border="0"></a></noscript>
<!-- Histats.com END -->
</body>
</html>