Slide 1

Slide 1 text

A few things you need to know about CSS
 
 
 @sheiko

Slide 2

Slide 2 text

What the heck is CSS anyway?

Slide 3

Slide 3 text

CSS is a declarative language used for describing look & feel of a document

Slide 4

Slide 4 text

MACHINE-READABLE DOCUMENT Data XML, HTML, SVG, …

Slide 5

Slide 5 text

adding some style Data Look & Feel ? XML, HTML, SVG, … CSS

Slide 6

Slide 6 text

XML, HTML, SVG, … HUMAN-READABLE DOCUMENT Data CSS Look & Feel

Slide 7

Slide 7 text

The basics

Slide 8

Slide 8 text

Hello World


 h1 { color: yellow; font-size: 2.4em; } HTML CSS OUTPUT Hello World

Slide 9

Slide 9 text

Hello World


 .hello { color: yellow; font-size: 2.4em; } HTML CSS OUTPUT Hello World

Slide 10

Slide 10 text

h1 { color: black; font-size: 2.4em; } rule CSS

Slide 11

Slide 11 text

h1 { color: black; font-size: 2.4em; } selector declaration CSS

Slide 12

Slide 12 text

h1 { color: black; font-size: 2.4em; } property value CSS

Slide 13

Slide 13 text

Selectors

Slide 14

Slide 14 text

Hello

h1 em { color: yellow; } h1 a em { color: yellow; } h1 a > em { color: yellow; } HTML CSS OUTPUT Hello World

Slide 15

Slide 15 text

Inheritance

Slide 16

Slide 16 text

Hello


 body { color: white; } h1 { color: yellow; } HTML CSS OUTPUT

Slide 17

Slide 17 text

Hello


 body { color: white; } h1 { color: yellow; } HTML CSS OUTPUT Hello World

Slide 18

Slide 18 text

Specificity

Slide 19

Slide 19 text


 Hello World


.parent .child { color: white; } h1 em { color: yellow; } HTML CSS OUTPUT

Slide 20

Slide 20 text


 Hello World


.parent .child { color: white; } h1 em { color: yellow; } HTML CSS OUTPUT Hello World

Slide 21

Slide 21 text

What else you can do with CSS

Slide 22

Slide 22 text

Turning elements into graphical shapes

Slide 23

Slide 23 text

div{ width: 200px; height: 200px; background: yellow;
 } HTML CSS OUTPUT

Slide 24

Slide 24 text

div{ width: 200px; height: 200px; background: yellow; border-radius: 20px; } HTML CSS OUTPUT

Slide 25

Slide 25 text

div{ width: 200px; height: 200px; background: yellow; border-radius: 50%; } HTML CSS OUTPUT

Slide 26

Slide 26 text

div{ width: 0; height: 0; border-width: 200px; border-style: solid; border-color: transparent; border-top-color: yellow; } HTML CSS OUTPUT

Slide 27

Slide 27 text

div{ width: 0; height: 0; border-width: 200px; border-style: solid; border-color: transparent; border-top-color: yellow; border-right-color: red; border-bottom-color: white; border-left-color: green; } HTML CSS OUTPUT

Slide 28

Slide 28 text

Multiple gradients

Slide 29

Slide 29 text

Complex graphics of a single DIV a.singlediv.com

Slide 30

Slide 30 text

Animated graphics codepen.io/hakimel/pen/aIhkf

Slide 31

Slide 31 text

Interactive UI

Slide 32

Slide 32 text

On :target .login { display: none; } .login:target { display: block; } HTML CSS OUTPUT

Slide 33

Slide 33 text

Checkbox hack
.menu-view, .menu-state { display: none; } .menu-state:checked + .menu-view { display: block; } HTML CSS

Slide 34

Slide 34 text

Checkbox hack • Custom Radio Buttons and Checkboxes • Tree menu • Tabbed areas • Dropdown menus • Push Toggles

Slide 35

Slide 35 text

What you shall not do with CSS

Slide 36

Slide 36 text

Avoid CSS inline styles

lorem ipsum

lorem ipsum HTML

Slide 37

Slide 37 text

Do not use IDs for styling BAD

 #widget { border: 1px solid #357ebd; } GOOD

 .widget { border: 1px solid #357ebd; } CSS CSS

Slide 38

Slide 38 text

Never use !important reactively BAD .toolbar .btn { border: none !important; } .btn { border: 1px solid #357ebd; width: 200px; }
 CSS

Slide 39

Slide 39 text

Do not override styles, but extend BAD .btn { border: 1px solid #357ebd; width: 200px; } 
 .toolbar .btn { border: none; } GOOD .btn { width: 200px; } 
 .btn-outlined { border: 1px solid #357ebd; } CSS CSS

Slide 40

Slide 40 text

How you shall deal with CSS

Slide 41

Slide 41 text

Be aware that browsers read selectors from right to left

Slide 42

Slide 42 text

.feed nav ul li h2 CSS

Slide 43

Slide 43 text

h2 h2 h2 h2 h2 h2 h2 h2 h2 li li li li li li li li li li ul ul ul u nav nav CSS

Slide 44

Slide 44 text

h2 h2 h2 h2 h2 h2 h2 h2 h2 li li li li li li li li li li ul ul ul u nav nav .feed CSS

Slide 45

Slide 45 text

h2 h2 h2 h2 h2 h2 h2 h2 h2 li li li li li li li li li li ul ul ul u nav nav .feed CSS

Slide 46

Slide 46 text

.feed nav ul li h2 .feed-heading CSS

Slide 47

Slide 47 text

Use relative typography

Slide 48

Slide 48 text

/* Global scope */ html { font-size: 62.5%; /* 10px */ } /* Components */ .header { font-size: 1.6rem; } /* scale with components */ h1 { font-size: 2em; } Lorem ipsum Lorem ipsum 16px h1: 32px .header CSS OUTPUT

Slide 49

Slide 49 text

/* Global scope */ @media (max-width: 960px) { html { font-size: 56.25%; /*9px*/ } } /* Components */ .header { font-size: 1.6rem; } /* scale with components */ h1 { font-size: 2em; } Lorem ipsum Lorem ipsum 14.4px h1: 28.8px .header CSS OUTPUT

Slide 50

Slide 50 text

Split your CSS into modules

Slide 51

Slide 51 text

@import "./main-menu.css"; @import "./panel.css"; MAIN.CSS PANEL.CSS /* Here go style for panel widget only */ .panel { } BUTTONS.CSS /* Here go styles for any buttons used in the project */ .btn { } @import "./buttons.css";

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Thank you!

Slide 54

Slide 54 text

Dmitry Sheiko dsheiko.com @sheiko https://github.com/dsheiko