https://www.flickr.com/photos/h-k-d/5093579727/
Futureproof styling
(in Drupal 8)
by Tamás Hajas
Slide 2
Slide 2 text
Tamás Hajas
Drupal / Web Project Manager &
Front-end Developer
Integral Vision Ltd
https://thamas.github.io
Slide 3
Slide 3 text
CSS is
easy
Slide 4
Slide 4 text
more than
300
.css files in Drupal 8.0.0
325
Slide 5
Slide 5 text
almost
116 000
characters in CSS loaded by Drupal 8.0.0
115 894
Slide 6
Slide 6 text
CSS is
easy
to do
wrong!
Slide 7
Slide 7 text
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
Slide 8
Slide 8 text
Ask
yourself!
Slide 9
Slide 9 text
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
Slide 10
Slide 10 text
@if body {
@if .node-19 {
@if #sidebar-first {
@if div {
@if .block {
@if .title {
@if a {
color: red !important;
}
}
}
}
}
}
}
Cyclomatic Complexity
Slide 11
Slide 11 text
KISS
http://chamaeleontour.com/2014/02/25/kiss-forever-band-hungary-in-melle/
Slide 12
Slide 12 text
Keep It Simple,
Stupid
http://chamaeleontour.com/2014/02/25/kiss-forever-band-hungary-in-melle/
Slide 13
Slide 13 text
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
Are you sure, it is red, because it is in…
… .title?
… .block?
… #sidebar-first?
… body?
Context?
Slide 14
Slide 14 text
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
Are you sure, it is red, because it is in…
… .title?
… .block?
… #sidebar-first?
… body?!
Context?
Seriously?!
Slide 15
Slide 15 text
“Basically,
cosmetics should
not change
depending on the
location of the
component.”
–Harry Roberts
Slide 16
Slide 16 text
#sidebar-first div.block .title a {
color: #fff;
}
Undoing things :(
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
div.block .title a {
color: #333;
}
Slide 17
Slide 17 text
Specificity :(
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
0001 0001 0001
0010 0010
0010 0100
0,1,3,3
Open / Closed principle
for extension for modification
.button {
…
padding: 1em 2em;
}
#sidebar .button {
padding: 1.5em 2.5em;
}
It is modified
by “context”
Slide 35
Slide 35 text
Open / Closed principle
for extension for modification
.button {
…
padding: 1em 2em;
}
.button--large {
padding: 1.5em 2.5em;
}
Slide 36
Slide 36 text
Classicists?!
Slide 37
Slide 37 text
body.node-19 #sidebar-first div.block .title a {
color: red !important;
}
Is this better?
Slide 38
Slide 38 text
Wait! It’s Drupal!
Slide 39
Slide 39 text
No! It’s Drupal 8!
Slide 40
Slide 40 text
• Forgot Classy! Use Stable!
• Forgot about Drupal!
• Use a Styleguide!
Think!
Slide 41
Slide 41 text
Templates
Slide 42
Slide 42 text
You can use Sass
mixins and extends*
* if it is needed
“Don’t make
me think!”
https://www.flickr.com/photos/mugley/2594318333
Slide 65
Slide 65 text
Use strict
Slide 66
Slide 66 text
Be consistent!
Slide 67
Slide 67 text
Lint!
Slide 68
Slide 68 text
1. Think & Decide
2. Communicate
3. Use strict
Slide 69
Slide 69 text
Credits This presentation…
…is based on the works of
Harry Roberts.
@see http://csswizardry.com
…is influenced by the talk
“Pains in CSS” by
Anikó Fejes.
@see http://slides.com/anikofejes/
css-programozoknak-4
Slide 70
Slide 70 text
Tamás Hajas
Drupal / Web Project Manager
Front-end Developer
thamas.github.io