, thus introducing confusion as far as where the main page header landmark is when using a screenreader.
All of which leads to Martin to a third approach, where the heading should be directly in the content, outside of the
This way:
- The
landmark is preserved (as well as its
role). - The
is connected to thecontent. - Navigating between the
and
is predictable and consistent.
As Martin notes: “I’m really nit-picking here, but it’s important to think about things beyond the visually obvious.”
“Fluid Headings”
Donnie D’Amato:
There’s no shortage of posts that explain how to perform responsive typography. […] However, in those articles no one really mentions what qualities you are meant to look out for when figuring out the values. […] The recommendation there is to always include a non-viewport unit in the calculation with your viewport unit.
To recap, we’re talking about text that scales with the viewport size. That usually done with the clamp() function, which sets an “ideal” font size that’s locked between a minimum value and a maximum value it can’t exceed.
.article-heading {
font-size: clamp(, , );
}
As Donnie explains, it’s common to base the minimum and maximum values on actual font sizing:
.article-heading {
font-size: clamp(18px, , 36px);
}
…and the middle “ideal” value in viewport units for fluidity between the min and max values:
.article-heading {
font-size: clamp(18px, 4vw, 36px);
}
But the issue here, as explained by Maxwell Barvian on Smashing Magazine, is that this muffs up accessibility if the user applies zooming on the page. Maxwell’s idea is to use a non-viewport unit for the middle “ideal” value so that the font size scales to the user’s settings.
Donnie’s idea is to calculate the middle value as the difference between the min and max values and make it relative to the difference between the maximum number of characters per line (something between 40-80 characters) and the smallest viewport size you want to support (likely 320px which is what we traditionally associate with smaller mobile devices), converted to rem units, which .
.article-heading {
--heading-smallest: 2.5rem;
--heading-largest: 5rem;
--m: calc(
(var(--heading-largest) - var(--heading-smallest))
/ (30 - 20) /* 30rem - 20rem */
);
font-size: clamp(
var(--heading-smallest),
var(--m) * 100vw,
var(--heading-largest)
);
}
I couldn’t get this working. It did work when swapping in the unit-less values with rem. But Chrome and Safari only. Firefox must not like dividing units by other units… which makes sense because that matches what’s in the spec.
Anyway, here’s how that looks when it works, at least in Chrome and Safari.
Style :headings
Speaking of Firefox, here’s something that recently landed in Nightly, but nowhere else just yet.
Alvaro Montoro:
Styling headings in CSS is about to get much easier. With the new
:headingpseudo-class and:heading()function, you can target headings in a cleaner and more flexible way.
:heading: Selects allelements.:heading(): Same deal, but can select certain headings instead of all.
I scratched my head wondering why we’d need either of these. Alvaro says right in the intro they select headings in a cleaner, more flexible way. So, sure, this:
:heading { }
…is much cleaner than this:
h1, h2, h3, h4, h5, h6 { }
Just as:
:heading(2, 3) {}
…is a little cleaner (but no shorter) than this:
h2, h3 { }
But Alvaro clarifies further, noting that both of these are scoped tightly to heading elements, ignoring any other element that might be heading-like using HTML attributes and ARIA. Very good context that’s worth reading in full.
Headings: Semantics, Fluidity, and Styling — Oh My! originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.
from CSS-Tricks https://ift.tt/KZGxJmf
Gain $200 in a week
via Read more