Slide 1

Slide 1 text

J. Román Hdez @Manz StarWorkShop CSS Clone Wars

Slide 2

Slide 2 text

StarWorkShop bit.ly/cssjsday

Slide 3

Slide 3 text

twitter.com/manz He trabajado / colaborado con

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Requisitos para el taller ¡Necesitas tenerlos instalados! NodeJS 8+ Git Inkscape VSCode

Slide 6

Slide 6 text

Plantilla con Parcel https://github.com/ManzDev/starworkshop-jsday $ git clone https://github.com/ManzDev/starworkshop-jsday $ cd starworkshop-jsday $ rm -rf .git $ npm install

Slide 7

Slide 7 text

Localización de los ficheros https://github.com/ManzDev/starworkshop-jsday reto1/ index.pcss index.js index.html

Slide 8

Slide 8 text

Scripts de NPM https://github.com/ManzDev/starworkshop-jsday npm run dev npm run build npm run deploy

Slide 9

Slide 9 text

Otras alternativas Para trabajar en el taller codepen.io webpack

Slide 10

Slide 10 text

global.pcss ¡Todos los retos tienen código común! :root { } /* Se aplica a la etiqueta HTML raíz (generalmente, ) */ body { } /* Reseteos (márgenes o evitar scroll) */ .container { } /* Un fondo gris ocupará toda la pantalla y centrará el contenido */

Slide 11

Slide 11 text

55 5 96 27 86 0 85 20 116 26 75 91 156 70 195 0

Slide 12

Slide 12 text

Reto #1 Tarjeta (Card) CSS

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

.container .card .image div h2 p .ok .cancel

Slide 15

Slide 15 text

EMMET Atajos para construcción HTML rápida .card .card>img.image .card>div*4

Slide 16

Slide 16 text

EMMET Atajos para construcción HTML rápida .card>img.image+(div>h2+p)+button.ok+button.cancel img.image[src="./mountain.jpg" alt="A mountain"]

Slide 17

Slide 17 text

postcss-font-magician Importa las tipografías de Google Fonts "automágicamente" font-family: 'Scope One', sans-serif; @font-face { font-family: "Scope One"; src: local('Scope One'), url('//scope-one.woff2') format('woff2') … url('//scope-one.woff') format('woff') … };

Slide 18

Slide 18 text

.card .image { } postcss-nesting Permite anidar CSS en PostCSS .card { & .image { /* … */ } };

Slide 19

Slide 19 text

font-size: 2rem; font-size: 1.5rem; rem units Unidades relativas "em" :root { font-size: 22px; } 44px 33px

Slide 20

Slide 20 text

grados (dirección) CSS Gradients Lineales o radiales lista de colores (se pueden añadir más) .card { background-image: linear-gradient( 22deg, #fff, #aaa); } cada color puede llevar un parámetro opcional (la longitud de ese color del gradiente)

Slide 21

Slide 21 text

desplazamiento en X CSS Shadows Sombras en "cajas" color de la sombra (usa RGBA con c. alfa) .card { box-shadow: 5px 5px 10px #111); } desenfoque (Más alto, más desenfoque) desplazamiento en Y inset (sombra "interna") factor de crecimiento (Más alto, más grande)

Slide 22

Slide 22 text

La imagen se adapta al tamaño del contenedor padre max-width Establece un tamaño máximo de ancho .image { max-width: 100%; }

Slide 23

Slide 23 text

CSS Custom Properties No son simplemente variables CSS (Cascada) button { background: linear-gradient(2deg, var(--button-color-top), var(--button-color-bottom)); &.ok { --button-color-top: #9088ec; --button-color-bottom: #665ce6; } &.cancel { … } }

Slide 24

Slide 24 text

postcss-color-mod-function Modificar un color con ciertas características .ok:hover { background: color-mod(#9088ec lightness(30%)); } https://www.w3.org/TR/css-color-4/#modifying-colors

Slide 25

Slide 25 text

tilt.js https://micku7zu.github.io/vanilla-tilt.js/ import tilt from 'vanilla-tilt'; const card = document.querySelector('.card'); const options = {}; tilt.init(card, options);

Slide 26

Slide 26 text

Reto #2 Pingüino CSS/JS que sigue con ojos al ratón

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

CSS Flexbox Cajas flexibles en CSS justify-content align-items .padre .hijo

Slide 29

Slide 29 text

CSS Flexbox Cajas flexibles en CSS .padre { display: flex; justify-content: center; align-items: center; } .padre { display: flex; justify-content: flex-start; align-items: flex-end; }

Slide 30

Slide 30 text

CSS Flexbox Cajas flexibles en CSS .padre { display: flex; justify-content: flex-start; align-items: flex-end; } .padre { display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-end; } row (default) column

Slide 31

Slide 31 text

CSS Flexbox Cajas flexibles en CSS .padre { display: flex; justify-content: space-between; align-items: flex-end; } .padre { display: flex; justify-content: space-around; align-items: flex-end; }

Slide 32

Slide 32 text

CSS Calc Realiza operaciones .elemento { --size: 200px; width: calc(var(--size) * 2); /* 400px */ } ...o incluso mezclar unidades a priori incompatibles: por ejemplo, una suma de porcentajes + píxeles

Slide 33

Slide 33 text

CSS Triangle ¿Un triángulo con CSS? .triangle { width: 0; height: 0; border: 25px solid transparent; border-top-color: #f1af16; }

Slide 34

Slide 34 text

Transiciones CSS Suavizando cambios .elemento { background: red; transition: background 1.5s; &:hover { background: blue } } 1.5 seg

Slide 35

Slide 35 text

Transformaciones CSS Moviendo cosas con la GPU .pupil { width: var(--pupil-size); height: var(--pupil-size); transform: translate(var(--eye-x), var(--eye-y)); transition: transform 0.5s ease; } --eye-y : 0 --eye-x : 0

Slide 36

Slide 36 text

Cambiar varCSS desde JS ¡Cambiando Custom Properties desde JS! const leftEye = document.querySelector('.left.eye'); leftEye.style.setProperty('--eye-x', `${x}px`); --eye-x : -10 --eye-y : 0 leftEye.getBoundingClientRect().x event.clientX (onMouseMove event)

Slide 37

Slide 37 text

Reto #3 Carta 3D girando

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

.container .card-container .card .back .animation .card .front .thumbs .hide .animation ♥ .items ♥ ♥

Slide 40

Slide 40 text

CSS Position Posicionamiento relativo .elemento { position: relative; top: 20px; left: -20px; } 20px 20px .elemento { position: absolute; top: 0; left: 0; } .padre (relative)

Slide 41

Slide 41 text

CSS Before/After Pseudo elementos (contenido generado) .thumbs::before { content: '3♥'; position: absolute; top: 10px; left: 10px; } ::after (absolute) (relative) .thumbs ::before (absolute)

Slide 42

Slide 42 text

Animaciones CSS Animar elementos con CSS @keyframes spin { 0% { transform: rotateY(0) rotateX(2deg) rotateY(5deg); } 100% { transform: rotateY(-360deg) rotateX(2deg) rotateY(5deg); } } .animation { animation: spin 5s linear infinite; } .hide { backface-visibility: hidden; } rotateY() rotateX() rotateZ()

Slide 43

Slide 43 text

Reto #4 Javascript guy

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

.container .js-guy .legs .left .js-body JS span .right

Slide 46

Slide 46 text

Font Face Tipografías que no están en Google Fonts @font-face { font-family: 'Neutra Text'; src: local('Neutra Text'), url('neutra.woff2') format('woff2'), url('neutra.woff') format('woff'), url('neutra.ttf') format('truetype'), } .js-body { font-family: 'Neutra Text', sans-serif; font-size: 172px; } JS

Slide 47

Slide 47 text

Z-index Profundidad en capas CSS .capa-frontal { position: relative; z-index: 2; } .capa-trasera { position: relative; z-index: 1; } /* Para que z-index funcione, position debe ser diferente a static (valor por defecto) */ 1 2

Slide 48

Slide 48 text

SVG Gráficos vectoriales en una web $ svgo leg.svg -p 0 --pretty -o leg.min.svg leg:svg: Done in 51 ms! 2.102 KiB - 90% = 0.21 KiB SVGO https://github.com/svg/svgo https://jakearchibald.github.io/svgomg/

Slide 49

Slide 49 text

Howler.js Audio fácil y rápido en web import thugSong from './thug-life.mp3'; import { Howl } from 'Howler'; const audio = new Howl({ src: [thugSong], loop: true, volume: 0.5, }); audio.play(); let id; … id = audio.play(id); /* No crea nuevas instancias de audio */

Slide 50

Slide 50 text

Reto #5 Vinilo de Pink Floyd

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

.container .prism (SVG inline) .box .stick .vinyl .rainbow .light

Slide 53

Slide 53 text

Selector + Elemento que está a continuación .box + .vinyl { position: relative; left: -200px; z-index: 1; transform: rotateZ(180deg); } .vinyl .box:hover + .vinyl { left: 100px; transform: rotateZ(180deg); } .box rotateZ() left

Slide 54

Slide 54 text

Perspective Profundidad y perspectiva en CSS .box { perspective: 10em; } .rainbow { transform: rotateX(35deg); } /* Si aumentamos y reducimos los valores, veremos el efecto de profundidad */ .rainbow .box

Slide 55

Slide 55 text

Fader con Howler Jugando con el audio const audio = new Howl({ src: [timeSong], loop: true, seek: 54, volume: 0, }); const playMusic = () => { id = audio.play(id); audio.fade(0, 1, 2000, id); }; fade(from, to, duration, [id]) from: Number Volume to fade from (0.0 to 1.0). to: Number Volume to fade to (0.0 to 1.0). duration: Number Time in milliseconds to fade. id: Number optional The sound ID. If none is passed, all sounds.

Slide 56

Slide 56 text

Reto #6 Panel de control de Kitt (Knight Rider)

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

5 rows 3 cols

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

.container .yellow .kitt-panel .yellow .voice- container .yellow .yellow .red .red .red .red .red .red .low- panel

Slide 61

Slide 61 text

Grid CSS Cuadrículas o "rejillas" CSS .kitt-panel { display: grid; grid-template-rows: repeat(5, 1fr); grid-template-columns: 1fr 3fr 1fr; grid-gap: 60px 20px; } .kitt-panel { width: 600px; height: 600px; } 1fr 1fr 3fr

Slide 62

Slide 62 text

Grid CSS Cuadrículas o "rejillas" CSS .voice-container { grid-row: 1 / span 3; grid-column: 2; } 1 .yellow .yellow .voice- container .yellow .yellow .red .red .red .red .red .red .low- panel 2 3 1 2 3 4 5

Slide 63

Slide 63 text

Grid CSS Cuadrículas o "rejillas" CSS .low-panel { grid-row: 4 / span 2; grid-column: 2; } .yellow .yellow .voice- container .yellow .yellow .red .red .red .red .red .red .low- panel 1 2 3 1 2 3 4 5

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

17 rows x 3 cols 3 rows x 2 cols

Slide 66

Slide 66 text

.voice-container .voice .cell .cell .cell .low-panel .low-grid .big.green .darky .big.yellow .darky .big.red .darky .off

Slide 67

Slide 67 text

Kitt cells Celdas del simulador de voz de Kitt .cell[data-color="0"] { background: #200000; } .cell[data-color="1"] { background: #4d0000; } .cell[data-color="2"] { background: #8d0000; } /* No se usa */ .cell[data-color="3"] { background: #fa0000; } renderKitt(4); paintKitt(0, 3); paintKitt(1, 4); paintKitt(2, 3); 20ms 4 } setInterval(fx, ms);

Slide 68

Slide 68 text

Reto #7 VHS de StarWars en el espacio

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

.container .vhs .top .center #galaxy .tape.a .film .circle .tape.b .film .circle .label

Slide 71

Slide 71 text

CSS Overflow Ocultar desbordamiento en el "interior" de una etiqueta .tape { width: 150px; height: 150px; background: black; overflow: hidden; } .circle .tape .circle { width: 400px; height: 400px; border-radius: 50%; background: blue; }

Slide 72

Slide 72 text

Canvas ¡Dibujar en un lienzo! #galaxy { position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 0; } VHS canvas

Slide 73

Slide 73 text

Canvas ¡Dibujar en un lienzo! const C = ['#444', '#888', '#fff']; const STAR = { x: rnd(0, canvas.width), y: rnd(0, canvas.height), speed: rnd(1, MAX_SPEED), color: rnd(0, C.length), }

Slide 74

Slide 74 text

Reto #8 Cartucho de Super Mario Bros (NES)

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

bricks.png fireball.png seal.png wash.png mario.png

Slide 77

Slide 77 text

Pretendo La tipografía de Nintendo ¿Eres capaz de encontrarla y convertirla a los formatos necesarios?

Slide 78

Slide 78 text

CSS Clip-path ¡Recortes personalizados en CSS! .tape { clip-path: polygon(50% 0%, 0% 100%, 100% 100%); } (50%, 0%) (x, y) (0%, 100%) (100%, 100%) Tool: Clippy

Slide 79

Slide 79 text

¡Gracias! José Román Hdez @Manz