HTML5 e Css3 - 6 | WebMaster & WebDesigner

38
HTML5 e Css3 [6] Matteo Magni

description

Sesta lezione Modulo HTML5 e Css3 per il corso di WebMaster & WebDesigner

Transcript of HTML5 e Css3 - 6 | WebMaster & WebDesigner

Page 1: HTML5 e Css3 - 6 | WebMaster & WebDesigner

HTML5 e Css3 [6]Matteo Magni

Page 2: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Quello che collega il nostro documento HTML ai nostri CSS sono essenzialmente i selettori.

Page 3: HTML5 e Css3 - 6 | WebMaster & WebDesigner

h1,h2,h3,h4,h5,h6,span,strong,p{color: purple }     h1,h2,h3,h4,h5,h6,span,strong,p,img{        border:1px solid #fff;        Font­size: 1.5em;    }   

Page 4: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Tramite quelle semplici i selettori possiamo attribuire le “regole” css ai vari elementi del nostro

DOM

Page 5: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Selettori di relazione

● Selettore di discendenti

div#container p {color: red}

● Selettore di figli (>)

body > p {color: red}

● Selettore di fratelli adiacenti (+)

li + li {margin­left: 10px; color: red}

● Selettore generale di fratelli (~)

h1 ~ h2 {color: red; text­decoration: underline}

Page 6: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Ma ci bastano?

Page 7: HTML5 e Css3 - 6 | WebMaster & WebDesigner

<style>.odd {background­color: yellow;}.even {background­color: red;}</style><tr class="odd"><td>text</td>...<td>text</td></tr><tr class="even"><td>text</td>...<td>text</td></tr>

Dobbiamo usare le classi

Page 8: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Nuovi Selettori

http://www.456bereastreet.com/archive/200601/css_3_selectors_explained/

Page 9: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Selettore di attributo - E[att^=”val”]

Seleziona ogni elemento E il cui valore di attributo att inizia con “val”.

object[type^="image/"]

Page 10: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Selettore di attributo – E[att$=”val”]

Seleziona ogni elemento E il cui valore di attributo att termina con “val”.

a[href$=".html"]

Page 11: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Selettore di attributo – E[att*=”val”]

Seleziona ogni elemento E il cui valore di attributo att contiene la sottostringa “val”.

p[title*="hello"]

Page 12: HTML5 e Css3 - 6 | WebMaster & WebDesigner

jQuery Like CSS syntax

Page 13: HTML5 e Css3 - 6 | WebMaster & WebDesigner

<input name="newsletter" /><input name="milkman" /><input name="newsboy" />

<script>$('input[name^="news"]').val('news here!');</script>

<input name="man­news" /><input name="milkman" /><input name="letterman2" /><input name="newmilk" /><script>$('input[name*="man"]').val('has man in it!');</script>

Page 14: HTML5 e Css3 - 6 | WebMaster & WebDesigner

PseudoClassi

Page 15: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:root

Seleziona l'elemento radice del documento. In HTML, l'elemento radice è sempre l'elemento HTML.

Page 16: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:nth-child(n)

Seleziona ogni elemento E che è l'n-esimo figlio del suo genitore.tr:nth­child(2n+1) /* represents every odd row of an HTML table */

tr:nth­child(2n)   /* represents every even row of an HTML table */

/* Alternate paragraph colours in CSS */

p:nth­child(4n+1) { color: navy; }

p:nth­child(4n+2) { color: green; }

p:nth­child(4n+3) { color: maroon; }

Page 17: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Passo delle formule

/*dispari */

tr:nth­child(2n+0)

tr:nth­child(2n)

 

/* pari */

tr:nth­child(2n+1)

 

tr:nth­child(10n­1)  /* 9, 19, 29, ecc */

tr:nth­child(10n+9) /* 9, 19, 29, ecc */

Page 18: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:nth-child(n)

● can take 'odd' and 'even' as arguments tr:nth­child(2n+1) /* represents every odd row of an HTML table */

tr:nth­child(odd)  /* same */

tr:nth­child(2n)   /* represents every even row of an HTML table */

tr:nth­child(even) /* same */

Page 19: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:nth-last-child(n)

Seleziona ogni elemento E che è l'n-esimo figlio del suo genitore, partendo dall'ultimo figlio.

tr:nth­last­child(­n+2)    

/* represents the two last rows of an HTML table */

foo:nth­last­child(odd)    

/* represents all odd foo elements in their parent element,counting from the last one */

Page 20: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:nth-of-type(n)

Seleziona ogni elemento E che è l'n-esimo fratello del suo tipo.

/*elementi p all'interno del div distanziati di 2*/

div p:nth­of­type(2n) {background­color: yellow}

Page 21: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:nth-last-of-type(n)

Seleziona ogni elemento E che è l'n-esimo fratello del suo tipo, partendo dall'ultimo fratello.

/* seleziono il penultimo p all'interno del div*/

div p:nth­last­of­type(2) {background­color: yellow}

Page 22: HTML5 e Css3 - 6 | WebMaster & WebDesigner

E:last-child E:first-child

Last:

Seleziona ogni elemento E che è l'ultimo figlio del suo genitore.

First:

Seleziona ogni elemento E che è il primo figlio del suo genitore.

Page 23: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:first-of-type

Seleziona ogni elemento E che è il primo fratello del suo tipo.//dl dt:first­of­type

<dl>

 <dt>gigogne</dt>

 <dd>

  <dl>

   <dt>fusée</dt>

   <dd>multistage rocket</dd>

   <dt>table</dt>

   <dd>nest of tables</dd>

  </dl>

 </dd>

</dl>

Non il terzo

Page 24: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe E:last-of-type

Seleziona ogni elemento E che è l'ultimo fratello del suo tipo.

tr > td:last­of­type

Page 25: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe

E:only-child

Seleziona ogni elemento E che è l'unico figlio del suo genitore.

E:only-of-type

Seleziona ogni elemento E che è l'unico fratello del suo tipo.

E:empty

Seleziona ogni elemento E che non ha figli (inclusi i nodi di testo)

Page 26: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe di destinazione

E:target

Seleziona un elemento E che è la destinazione dell'URL di riferimento.

*:target { color : red }

Page 27: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe di stato

E:enabled

Seleziona ogni elemento E dell'interfaccia utente (controllo di un form) che è abilitato.

E:disabled

Seleziona ogni elemento E dell'interfaccia utente (controllo di un form) che è disabilitato.

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

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

Page 28: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe di stato

E:checked

Seleziona ogni elemento E dell'interfaccia utente (controllo di un form) che viene selezionato.

input:checked { border:1px solid #090; }

E::selection

Seleziona la porzione di un elemento E attualmente selezionata o evidenziata dall'utente.

Page 29: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Pseudo-classe negazione

E:not(s)

Seleziona ogni elemento E che non corrisponde al selettore semplice s.

Page 30: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Supporto dei Browser?

http://kimblim.dk/css-tests/selectors/

Page 31: HTML5 e Css3 - 6 | WebMaster & WebDesigner
Page 32: HTML5 e Css3 - 6 | WebMaster & WebDesigner

TransizioniCss

Page 33: HTML5 e Css3 - 6 | WebMaster & WebDesigner

p { width: 200px;height: 200px;background­color: yellow;}   p:hover {background­color: red;}   

Page 34: HTML5 e Css3 - 6 | WebMaster & WebDesigner

p { width: 200px;height: 200px;background­color: yellow;transition­property: background­color;transition­duration: 5s;}   p:hover {background­color: red;}

   

Page 35: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Regole proprietarie

­webkit­transition­property: background­color; 

­webkit­transition­duration: 2s;

         

­o­transition­property: background­color;      

­o­transition­duration: 2s;

         

­moz­transition­property: background­color;   

­moz­transition­duration: 2s;

Page 36: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Attributi

● transition-property

proprietà a cui assegnamo la transizione

● transition-duration

durata della transizione in secondi (0 default)

Page 37: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Attributi

● transition-timing-function

Come si calcola il cambiamento:

ease, linear, ease-in, ease-out, ease-in-out, cubic-bezier

● transition-delay

ritardo nell'iniziare la transizione

Page 38: HTML5 e Css3 - 6 | WebMaster & WebDesigner

Domande?

Slide:

http://cypher.informazione.me/

Code:

https://github.com/inFormazione/Cypher/

mail:

[email protected]