Base styles
Layout styles
Module & state styles
Themes
More code =
negative lines of code
Since ~2009:
2015 and beyond:
“If a developer five years ago jumped off a bridge...”
html {
font-size: 62.5%;
}p {
font-size: 1.4rem; /* 14px */
}
.fancy-header {
font-size: 2.4rem; /* 24px */
}Makes the math easy
1.0em = 10px
html {
font-size: 62.5%;
}p {
font-size: 1.4rem;
}
.component {
font-size: 1.4rem;
}
.other-component {
font-size: 1.4rem;
}
.fancy-header {
font-size: 2.4rem;
}(but 👍 for using relative units)
Writing the same code over and over
html {
font-size: 87.5%;
}16 * .875 * 1.7 =
irrelevant
.fancy-header {
font-size: 1.7rem;
}h1, h2, h3, h4, h5, h6 {
margin-top: .667em;
margin-bottom: .667em;
font-weight: 500;
line-height: 1.1;
}
h1 { font-size: 2.25rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: .875rem; }
h6 { font-size: .75rem; }Usually fine if your site is mostly just text. But for a web app...
h1, h2, h3, h4, h5, h6 {
margin-top: .667em;
margin-bottom: .667em;
font-weight: 500;
line-height: 1.1;
}
h1 { font-size: 2.25rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: .875rem; }
h6 { font-size: .75rem; }.pagehead > h1 {
margin-top: 0;
margin-bottom: 0;
font-size: 1.25rem;
font-weight: normal;
line-height: 1.75;
}
...
.boxed-group > h3 {
margin: 0;
padding: .625em;
font-size: .875rem;
line-height: 1.2;
}h3
h3
h3
h3
h1
h1
h1, h2, h3, h4, h5, h6 {
margin: 0;
font-size: 1rem;
font-weight: normal;
line-height: inherit;
}.content {
h1, h2, h3, h4, h5, h6 {
margin-top: .667em;
margin-bottom: .667em;
font-weight: 500;
line-height: 1.1;
}
h1 { font-size: 2.25rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: .875rem; }
h6 { font-size: .75rem; }
}.tabs {
padding-left: 0;
list-style: none;
}
.tabs > li {
display: inline-block;
margin-right: .2em;
...
}
And when you need the bullets...
ul {
padding-left: 0;
list-style: none;
}.tabs {
// no code necessary!
}
.tabs > li {
display: inline-block;
margin-right: .2em;
...
}
.content {
ul {
padding-left: 2.5em;
list-style: bullet;
}
}
// -- or --
.bullet-list {
padding-left: 2.5em;
list-style: bullet;
}...bring them back
.container {
background: #fff;
border: 1px solid black;
padding: 1em;
width: 300px;
}
.widget {
height: 100px;
background: #369;
border: 1px solid black;
}.container {
background: #fff;
border: 1px solid black;
padding: 1em;
width: 300px;
}
.widget {
margin-top: 1em;
height: 100px;
background: #369;
border: 1px solid black;
}.container {
background: #fff;
border: 1px solid black;
padding: 1em;
width: 300px;
}
.widget {
height: 100px;
background: #369;
border: 1px solid black;
}
.widget + .widget {
margin-top: 1em;
}<section class="container">
<div class="widget">...</div>
<div class="widget">...</div>
<div class="dongle">...</div>
</section>* + * {
margin-top: 1em;
}Only apply “glue” between adjacent elements—regardless of what elements they are
Mix & match modules
Works with nesting
* + * {
margin-top: 1em;
}.grid-row > * {
margin-top: 0;
}.widget {
...
}
@media screen and (min-width: $breakpoint-small) {
.widget {
...
}
}
@media screen and (min-width: $breakpoint-medium) {
.widget {
...
}
}
@media screen and (min-width: $breakpoint-large) {
.widget {
...
}
}Ugh.
So much code.
“Websites aren't broken by default; they are functional, high-performing, and accessible. You break them.”
.tile {
display: inline-block;
width: 300px;
max-width: 100%;
}.container {
display: flex;
flex-wrap: wrap;
}.tile {
flex: 1;
min-width: 300px;
}.tile {
font-size: calc(.5em + 2vw);
}Simulate “min-font-size”
.form {
font-size: 1rem;
color: black;
}
input,
textarea,
select,
button {
padding: .5em;
font-size: 1em;
border-radius: .2em;
border: 1px solid currentColor;
color: inherit;
font-family: inherit;
}.form--large {
font-size: 1.4rem;
}.form--small {
font-size: .667rem;
}{
padding: .5em;
font-size: 1em;
border-radius: .2em;
}.form--red {
color: red;
}.form--blue {
color: blue;
}{
border: 1px solid currentColor;
color: inherit;
}