What is the best way to establish a default font-family for all elements on a website, without

Currently facing a dilemma: the stylelint rule "selector-max-universal": 0 is mandatory, while also needing to assign a default font family to text elements within a specific class.

This means I cannot simply use:

* { font-family: DefaultFont; }

Furthermore, code review discourages the use of such selectors (SCSS mixin) as well:

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

// Font assignments are tailored for certain classes
.theme-a {
@include setGlobalFontFamily;
}

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

//.theme-...

Theme classes are conditionally applied via JS to a container element, for example:

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

In addition, these font families need to be globally set in one file and only once per each theme class to ensure that other themes' font families do not override...

If anyone has a solution or workaround for this issue, please share!

Answer №1

If I'm understanding correctly, you can simply assign the font families directly to .style-a and .style-b like this:

.style-a {
   font-family: 'Another Font', sans-serif;
}

.style-b {
   font-family: 'Open Sans', sans-serif;
}

The descendants of these elements will automatically inherit the fonts unless they are specifically overridden. It's not necessary to individually set each element.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

New expanded choices in Bootstrap 5.3 for adjusting the size of the bottom border

As seen in the examples provided on the official Bootstrap borders guide, adjusting border width sizes using the border class seems straightforward... <span class="border border-1"></span> <span class="border border-2"> ...

Strange Appearance of Angular Material Slider

I am experiencing some issues with my slider and I'm not exactly sure what's causing them. [] .big-container { display: block; padding-left: 10px; padding-right: 10px; padding-top: 10px; margin-bottom: 10px; } .question { display ...

When using an iPhone 6+ in landscape mode with tabs open on Mobile Safari running iOS 8, the Bootstrap navbar-fixed-top may experience difficulty in

Encountered an issue with Bootstraps navbar-fixed-top on iPhone 6+ in landscape mode on iOS 8 when multiple tabs are open. To replicate the bug: 1) Visit http://getbootstrap.com/examples/navbar-fixed-top/ on iPhone 6+ in landscape mode with another tab ...

Having trouble opening the prompt window by clicking on the button

I have been given an assignment to check if a given number is an Armstrong number. However, I am facing an issue where the prompt window does not appear when I click the button. This issue only arises when the rest of the function is written out. If the ...

Compilation of SCSS is not possible due to a SASS error - there are no .sass files present

After successfully building an application using VueJS, I encountered a sudden error. Despite rolling back to previous versions, the error persists and I cannot pinpoint what caused it to appear out of nowhere. Invalid CSS after "/* banners */": expected ...

Tips for ensuring the correct size of images and their captions within a figure element

I'm struggling with the CSS for an image inside a figure. Here is the HTML: #content figure { display: inline-block; border: 1px solid #333333; height: 200px; margin: 10px; } #content img { height: 180px; background-size: auto 100%; b ...

css: Aligning fonts horizontally when they have varying sizes

First time asking a question on this platform! I'm attempting to achieve a "pixel perfect" horizontal alignment of two lines of text, with each line having a different font size. <style type="text/css"> * { font-family: sans-serif;} ...

Unable to see Primereact styles reflected on components

After some investigation, I've pinpointed the issue to be related to preflight from tailwind. Upon reviewing the documentation, I came across this helpful information: CSS Layer It seems that using Tailwind CSS with styled or unstyled modes of PrimeR ...

How can I incorporate custom text when hovering over dates on fullcalendar?

I'm looking to customize the mouseover text inside fullcalendar. Currently, the script only displays the event title on mouseover. You can see a working example here: JS Fiddle Example. How can I modify the code to show my own personalized text on mo ...

Tips for making a Google Map API Element fit perfectly in a Bootstrap column below a heading

I've spent countless hours trying to solve this on my own, scouring the internet for answers with no luck. I'm hoping someone here can spare a few moments to help me out. Much appreciated! I'm attempting to make the Google Maps API element ...

"Get rid of the arrow in Bootstrap's dropdown menu

I'm currently using a bootstrap template that features an accordion menu. However, I have come across a scenario on one section of the page where I do not require the items to expand and show additional text, therefore, I would like to remove the arro ...

JavaScript - continuously update the image marked as "active"

I have a collection of 4 pictures that I want to rotate through in my web application. Each picture should have the "active" class applied to it, similar to when you hover over an image. .active, .pic:hover{ position: absolute; border: 1px solid ...

Webkit causing complications with straightforward CSS3 animation

I'm currently working on a website and you can check it out here: Unfortunately, I've encountered an issue where the animations aren't triggering specifically on webkit browsers like Chrome and Safari: @-webkit-keyframes slideright{ 0% {tr ...

Css flex is not compatible with Safari, iPhone 5, and some mobile web browsers' webviews

All of the following code snippets are written in HTML: <div class="btn-toolbar text-center" role="toolbar"> <a href="#" class="btn btn-success">Link 1</a> <a href="#" class="btn btn-success">Link 11</a> < ...

What is the best way to conceal the outline in a popup window?

I have successfully implemented a popup/modal window using JavaScript, but now I need to find a way to hide the outline map container. The initialization code for the map is as follows: self.mapDialogOptions = { autoOpen: false, m ...

Utilizing the "row" and "column" attributes in Angular (Flexbox) results in significant spacing between input fields within the HTML code

I'm working on aligning 2 input fields side by side within the same line. To achieve this, I've been utilizing Flexbox. However, I've observed that when using Flex with both 'row' and 'column', it introduces extra spacing ...

The functionality of the Bootstrap dropdown list button is not functioning properly on mobile devices

Currently, I am in the process of developing a website and testing its mobile view on my iPhone. The website is still using bootstrap 3, but I have encountered some issues. When I tap on the navigation button on my iPhone, nothing happens - no dropdown lis ...

How come I am unable to connect my CSS to my EJS files?

Having difficulty linking my css files to my ejs files. Using a standard node.js/express setup, I'm attempting to connect my main.css file from the public/css directory to my index.ejs file in views. The html and routing are functioning correctly. Ple ...

Changing the color of buttons within the anchor and menu-separator classes in WordPress

https://i.sstatic.net/lYs6O.png Hi everyone, I'm new to WordPress and need help changing a green button to blue. I have found the button in an anchor tag with the class "menu-separator." Is there a way for me to write custom CSS to change its color? ...

Adding a Class with jQuery On Click Event

Trying to troubleshoot why this code isn't functioning: https://jsfiddle.net/bv6ort3g/ HTML: <div class="all-btn">All Button</div> <div class="item all"> item 1 </div> <div class="item all"> item 2 </div> <di ...