Applying the Saira SuperflyCSS Font Utility to an Element and its Children

Ole Ersoy
1 min readDec 23, 2020

--

Image by DavidRockDesign from Pixabay

Scenario

We have the following markup

<main>
<h1>Hello</h1>
<section>
<p>This should be styled with the Sara Font Utility</p>
</section>
</main>

And we want both the h1 and p element to be styled with the SuperflyCSS u-font-saira-400 utility.

Approach

The font-family property gets inherited by child elements, so all we need to do is apply the font utility u-font-saira-400 to the main element like this:

<main class="u-font-saira-400">
<h1>Hello</h1>
<section>
<p>This should be styled with the Sara Font Utility</p>
</section>
</main>

Prototype

To test this out first install the SuperflyCSS CLI:

npm i @superflycss/cli

Create a new project:

sfc new p
cd p

Then install the font utilities:

npm i @superflycss/utilities-fonts

Update src/test/css/index.css so that it looks like this:

@import "../../main/css/";
@import "@superflycss/utilities-fonts/google/saira";

And src/test/html/index.html with the html markup.

Then run the live server :

sfc s

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet

Write a response