Declare variables for various categories of courses

Currently working with SCSS and have a variable $arial: 'Arial', serif;

Now the plan is to implement the following:

.english{
    $arial: 'Arial', serif;
    font-family: $arial;
}
.japan{
    $arial: 'Noto Sans';
    font-family: $arial;
}

The initial intention was to display $arial as 'Arial' for the customer, but now they want separate styles for English and Japanese pages.

Answer №1

To achieve this, you can utilize a more modern CSS feature known as CSS variables. Simply specify which variables should change in a given context and then import them into the definitions themselves. For detailed information, refer to the documentation available at: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

Here's an example showcasing easily distinguishable fonts:

document.querySelector('h1').addEventListener('click', e => document.body.classList.toggle('japanese'))
body {
   
  --font: 'Comic Sans MS', monospace;
  
  font-family: var(--font, cursive);
    
}

body.japanese {

  --font: 'Impact';
  
}
<h1>Lorem Ipsum Dolor Sit Amet</h1>

By simply toggling a class, the variable gets updated without the need to redefine it multiple times.

Answer №2

If you're looking to enhance your website's design, I recommend utilizing CSS Variables as demonstrated in the example above. To achieve this stylishly, you can take advantage of Sass maps.

$map:("english":"'Arial',serif","japan":"'Nato Sans'");

@each $key , $value in $map{
  .#{$key}{
    font-family:unquote($value);
  }
}

Here is the expected output:

.english {
  font-family: 'Arial',serif;
}

.japan {
  font-family: 'Nato Sans';
}

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

Enhancing React Applications: Implementing Dynamic CSS Modifications

I have a component that includes an input slider controlled by radio buttons. <input checked={settings[0]?.payments.length === 1 ? 'checked' : null} type='radio' id={payment.value} value={payment.value} onChange={ settings[0] ...

Is there a way to enable scrolling in the background when a modal is open?

I recently designed a bootstrap modal, but I encountered an issue where when it appears, the vertical scrollbar on the background page becomes disabled and the content shifts to the right by the width of the scrollbar. I want to prevent this content shif ...

Tips for keeping a link in place on an image

Trying to place a link on a 1920x1080 picture and keep it fixed in one spot, regardless of browser size. Any suggestions? <!DOCTYPE html> <link rel="stylesheet" href="../style.css" /> <html> <head> ...

Discover more in React about using ellipses (...) with dangerouslySetInnerHTML

What is the best method for limiting the number of HTML lines retrieved using dangerouslySetInnerHTML in a React application and creating a '... Read More' expander for it? I attempted to use react-lines-ellipsis, but unfortunately the 'tex ...

Construct a Product Showcase Page" (FreeCodeCamp) - Issue "Incurred upon clicking a .nav-link button in the navigation panel

Hi there! I've been working on a page programming task, but I'm having trouble with the "№5 “When I click a .nav-link button in the nav element, I am taken to the corresponding section of the landing page.” error. Can anyone help me figure ...

Customizing the navbar to be inverse on each webpage using CSS, PHP, and Bootstrap

Dealing with a Bootstrap navbar across multiple pages on my website is becoming a hassle. Every time I need to make a change, I find myself jumping from one page to another just to update it. My objective is to have the ability to edit the navbar in one ce ...

Having Trouble Positioning Button at Bottom of Browser with Absolute Positioning in HTML and CSS

I am encountering an issue with positioning an element (<button id="foo">FAQ</button>). The CSS code I have for the button is: #foo { position: absolute; bottom: 0px;/* I have also tried using different units */ left: 0px;/* same t ...

Aligning Content in the Center of a CSS Grid

Having difficulty with a CSS Grid layout that should consist of 7 squares per row to create a calendar style design. The layout seems fine, but I am struggling to center the title and subtitle in the middle of each item. I have tried using margin:auto, ver ...

Font sizes for inline elements can be customized with gaps

Having trouble with setting font-size styles for inline elements, causing unexpected gaps to appear. Despite finding related questions on this issue, I have yet to discover a solution that fits my specific case. Here is the code in question: <!docty ...

Creating expandable and collapsible table sections within an HTML document are made possible using

This is an example of code similar to what I am currently working on. I am trying to create collapsible subsections within a table, where the main headers can be opened separately from the subheaders. The goal is for the initial view of the page to display ...

The div elements are not nested correctly as they should be

Essentially, I have a div element that contains a wrapper along with two other nested divs. One of these divs floats to the left while the other floats to the right. You can see how it appears here: Upon examining the code provided below, you'll not ...

How can I design a form that resembles the sign-in form used by Google?

Currently, I am in the process of creating a contact form for a website that is inspired by the design of Google's material sign-in form. I have successfully implemented an effect where clicking on the input field causes the label to change its posit ...

Position the form / delete button in alignment with the rest of the buttons

I have a table with options at the end like View, Edit, and Delete. I need the Delete button to be inside a form so that I can POST the delete request. However, my button/form is not aligning on the same line as expected. I have tried using the form-inlin ...

Troubleshooting problems with the CSS code for a progress bar in Gmail

I recently came across a unique progress bar design on Gmail and wanted to implement something similar. I found some code snippets on this webpage: . However, I encountered an issue where the progress bar was only displaying in Internet Explorer but not in ...

Troubleshooting problem with table reflow in Bootstrap v4.0.0-alpha.3 on mobile devices

I am having trouble fixing the table-reflow issue in mobile view while trying out the code below. Any suggestions on how to resolve this would be greatly appreciated. Check out the image here To see the code, visit CODEPEN <div class="container"> ...

I prefer to have the boxes lined up horizontally, but they seem to be arranged vertically

I'm struggling to get the color boxes to display horizontally with spaces between them. Currently, they are showing up vertically in a column layout. I want 4 smaller color boxes within a larger grey box at the top layer, with margins and padding app ...

Setting the default position of a scrollbar

In the chat window on my website, users currently have to use the scrollbar to navigate between messages when the log is filled. I want the chat frame to automatically display the last message at the bottom without requiring users to scroll. Can this be ac ...

The expression `Object.prototype.toString.call(currentFruit) === "[object Date]"` checks if the object referenced by `current

Hi, I'm just starting to learn JavaScript and I have a question about an if condition that I came across in my code. Can someone please explain what this specific if condition does? Object.prototype.toString.call(currentFruit) === "[object Date]& ...

Can CSS alone be used to provide a cover for auto-scaling images?

One common technique is using max-height and max-width to make an image automatically fit in a div, as shown below: .cover img { max-width: 100%; max-height: 100%; } But is there a way to create a translucent cover (with opacity set to 0.8) that ...

Streamlined Infinite Scrolling Data Visualization Using SVG Implemented in HTML and CSS

I have developed a dynamic graph that continuously updates with new data points being plotted. Right now, I am utilizing requestAnimationFrame() to render the element positions 30 times per second, but performance can be sluggish with numerous SVG element ...