|
|
|
|
|
by chrismorgan
4487 days ago
|
|
All those media queries! 500px ⇒ 14px
570px ⇒ 15px
620px ⇒ 16px
680px ⇒ 17px
720px ⇒ 18px
800px ⇒ 19px
860px ⇒ 20px
920px ⇒ 21px
1000px ⇒ 22px
This can be simplified a lot with the vw unit. 1vw = 1% of viewport width.The differences between each pixel increase in font size seem rather arbitrary: 70, 50, 60, 60, 80, 60, 60, 80. Let's simplify it, going for 14px below 500px, 22px above 1000px, and linear interpolation between widths 500px and 1000px. That way you can just use calc(). Oh, and I'll use `:root` instead of `html`, for joie de vivre. :root {
font-size: calc(6px + 1.6vw);
}
@media screen and (max-width: 500px) {
:root {
font-size: 14px;
}
}
@media screen and (min-width: 1000px) {
:root {
font-size: 22px;
}
}
If a browser doesn't support calc() or the vw unit, it will just keep the browser's default of 16px. |
|
I'm going to follow up to this post soon with a SASS mixin that gets around the @media query code bloat and lets you coordinate with globally named breakpoints.