How to set a global/default font-family without universal selectors?

CPHPython

I am in a conundrum: the stylelint rule "selector-max-universal": 0 is required and, at the same time, I need to provide a default font family to text elements within a certain class.

Therefore I am not able to use this:

* { font-family: Somefont; }

And, at the same time, code review requested me not to use these kind of selectors (SCSS mixin):

@mixin setGlobalFontFamily($family: Somefont) {
  button,
  div,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  label,
  p {
    font-family: $family, sans-serif;
  }
}

// fonts are specific to certain classes 
.theme-a {
   @include setGlobalFontFamily;
}

.theme-b {
   @include setGlobalFontFamily(Roboto);
}

//.theme-...

Theme classes are conditionally applied through JS to a container element, e.g.:

<body>
  <section class="theme-b">
  </section>
</body>

Additionnaly, these fonts families should be set globally in one file and only once per each theme class, guaranteeing that other theme font families are not shown...

Can anyone see a way to workaround this problem?

Zdravko Pernikov

If I understood correctly you can just set the font families directly to .theme-a and .theme-b e.g.:

.theme-a {
   font-family: 'Some Font', sans-serif;
}

.theme-b {
   font-family: 'Roboto', sans-serif;
}

The children of those elements should inherit the fonts automatically if something doesn't overwrite them. There's no need of setting each element manually.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to set font family but retain fallback stack?

How to set default font family in React Native?

How to set the font family I want in css?

how to change font size of label without changing font family in xcode

how to set specific font family for each locale in jetpack compose

How to set the font-family as specified when editing post in wordpress?

How to set default font family for entire Android app

how to set the UIFont family and name with display font on the UITableView?

How to set a font family to an entire Word document in Apache POI XWPF

How to set the font-family like a digital clock CSS?

How to Set a Custom Font Family in the Xamarin ActionBar Title?

how to set default font family available in android to action bar title

How to set a font family to "erewhon" when using Latex in matplotlib?

Set display font family in wxhaskell?

How to change a widget's font style without knowing the widget's font family/size?

How can I set the font-family & font-size inside of a div?

How to set a CSS font-family using JQuery when the font name has a space

How to set column colors, title colors , font size , font family in external css file for highcharts?

how to override bootstrap font family?

how to change font family of sweetalert

How to change levelplot font family?

How to change the font family of Highchart to Bootstrap css default font family

How to create custom font family with bold font

How to use a specific font from a font family

Dompdf and set different font-family

Set font family and size of equations in flextable

Set font-family to specific symbols in CSS

Set font family and color in png plot device

Unable to set Font Family in my web page