Based on inherited font-size
.parent {
font-size: 16px;
}
.parent > .child {
font-size: 1.2em; /* 19.2px */
}
Same declared value; different computed value
.tile {
font-size: 1.2em; /* 19.2px */
margin: 1.2em; /* 23.04px */
padding: 1.2em; /* 23.04px */
border-radius: 1.2em; /* 23.04px */
}
font-size: 16px
font-size: 1.2em // 19.2px
font-size: .875em // ???
font-size: .9em // this is ridiculous
ul {
font-size: 0.8em;
}
“Root em”—relative to font size of root element (<html>
)
ul {
font-size: 0.8rem;
}
By default, use:
When in doubt, us ems
Use unitless numbers for line-height
14px / 16px = 0.875em
18px / 14px = 1.2857em
24px / 13π = STOP IT
Use a scalar...
...to calculate px font sizes...
...to reverse back out to an em scalar 🤔
Scalar: 1.25em
— always produces next font size up
Inverse scalar: 0.8em (1 / 1.25)
— always produces next font size down
Delegate responsibility to it
Two options:
.tile {
border: 2px solid white;
padding: 7px 15px;
border-radius: 5px;
margin-bottom: 15px;
font-size: 16px;
}
.tile__title {
font-size: 14px;
text-transform: uppercase;
}
.tile--small {
padding: 4px 10px;
border-radius: 3px;
margin-bottom: 10px;
font-size: 10px;
}
.tile--small > .tile__title {
font-size: 8px;
}
{ font-size: 1rem; }
{ font-size: 0.8em; }
{ font-size: 1em; }
{ font-size: 1.2em; }
.tile {
border: 2px solid white;
padding: 0.6em 1.2em;
border-radius: 0.3em;
margin-bottom: 1em;
font-size: 1rem;
}
.tile__title {
font-size: 0.8em;
text-transform: uppercase;
}
.tile--small {
font-size: 0.625rem;
}
.tile--large {
font-size: 1.3rem;
}
Hold RESET while you turn POWER off!!
Hold RESET while you turn POWER off!!
Hold RESET while you turn POWER off!!
Use rem for global sizing
Use em for local sizing
.tile {
border: 2px solid #000;
padding: 0.6em 1.2em;
border-radius: 0.3em;
margin-bottom: 1em;
font-size: 1rem;
}
.tile__title {
font-size: 0.8em;
text-transform: uppercase;
}
.dropdown__toggle::after {
content: "";
position: absolute;
right: 1em;
top: 1em;
border: 0.3em solid;
border-color: black transparent transparent;
}
.twitter > img {
height: 1em;
width: 1em;
vertical-align: -0.1em;
}
SVG FTW!
a:link {
text-decoration: none;
box-shadow: inset 0 -0.1em 0 0 #cef;
transition: box-shadow 0.2s ease-in-out;
color: #346;
}
a:hover {
box-shadow: inset 0 -1.2em 0 0 #cef;
}
:root {
font-size: 0.8em;
}
@media (min-width: 35em) {
:root {
font-size: 1em;
}
}
@media (min-width: 50em) {
:root {
font-size: 1.25em;
}
}
:root {
font-size: 2vw;
}
:root {
font-size: calc(0.5em + 1vw);
}
:root {
--font-color: black;
}
.inverse {
background-color: black;
--font-color: white;
}
.tile {
color: var(--font-color);
border-color: var(--font-color);
}
.alert {
color: blue;
background-color: color(currentColor lightness(+50%));
border: 1px solid currentColor;
}
.alert--danger {
color: red;
}
.alert--warning {
color: orange;
}
hue, saturation, lightness, red, green, blue,
whiteness, blackness, tint, shade, blend, contrast
demo (PostCSS)
Ems are most powerful when you fully embrace them
manning.com/books/css-in-depth
50% off code: mlgrant2
Web