Creating universal styles in CSS Modules using SCSS

Is there a way to use a global class in CSS Modules and SCSS effectively?

According to my interpretation of the CSS Module's documentation on Composing from global class names, the suggested approach is:

:global {
  .bar {
    color: purple;
  }
}

.my-icon {
  composes: bar from global;
}

However, when I try this method, I encounter the error message:

referenced class name "bar" in composes not found

Can someone guide me on how to correctly compose from a global class in this scenario?

Answer №1

If you want to achieve this, use the following code:

:global(.bar) {
  color: red;
}

.myIcon {
  composes: bar from global;
}

Check out a sandbox I set up with a

https://i.sstatic.net/E1cgd.png

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

Guide to displaying WordPress functions within an accordion in my loop

Currently, I'm working on implementing a vertical accordion feature that will display blog posts within each section. The idea is to have 5 of the most recent posts displayed in the accordion, with each post showing the date (day/month/year) and title ...

the display:block property totally ruins my aesthetic

I'm facing an issue with filtering a table using an input box within one of the elements. Whenever I type something in the input box, the table automatically filters its rows based on the input. The strange thing is that when I try to use display:bl ...

When making changes to the className in CSS transitions may lag a step behind

I am currently working on a form where the steps slide in as cards. For example, when transitioning from step 1 to step 2, the card appears from the right, and when going back from step 3 to step 2, the card slides in from the left. However, I am facing a ...

What is the best way to position a sticky element on top of an image?

When designing my website, I encountered an issue with a "sticky element" and a series of images below it. As I scroll down, the "sticky element" ends up hiding behind the images, making it invisible. I'm seeking a solution to keep the "sticky element ...

Distressed and worn border style achieved with CSS

I'm attempting to replicate the unique teal colored border shown in the image link below: https://i.sstatic.net/RewiB.png The border displayed has an irregular pattern, with random breaks and fades. If achieving an exact match is not possible, I wou ...

Testing the screen size automatically using Javascript

Hello everyone, I've implemented a JavaScript code that triggers an image to slowly appear and darken the background when a link is clicked. However, on an iPad, the background doesn't completely turn black as intended. The CSS specifies that the ...

Can you please explain the meaning of this wildcard symbol?

We recently came across a part of our grunt file that was written by a former colleague. While the code functions correctly, the specific purpose of one segment remains a mystery to us! Here is the enigmatic code snippet: dist: { files: [{ ex ...

When importing both shared-lib and MUI in my ReactJS application, I noticed that my custom MUI styles were being overwritten by the MUI styles

I have developed a shared library using React and Storybook. Within this library, I am utilizing the MUI V5 Button and making some style modifications using CSS modules. I executed the "build&pack" script in my library, which generated a tgz package that ...

What causes the discrepancy in animations between these two divs?

I am facing an issue with two divs that have different animations applied to them. Even though the animations are different, they are not working as expected. Here is the code snippet: $(document).ready( function(){ $('#show_hide_button').clic ...

Is there a way to horizontally position text in the center of a span within a table cell using only the span's CSS?

I need to horizontally align text inside a specific table cell, but the HTML code is from a third-party source. I am only able to modify the style of the span element. .Change { text-align: center; } <table> <tr> <td>Some rando ...

The display of data in Datatables is malfunctioning

I have already included the provided CDN on the website but I am still unable to display any results even after copying and pasting every line of code. Here is the CDN <link rel="stylesheet" type="text/css" href="https://cdn.d ...

"Effortlessly slide up or down with jQuery Dropdown: smooth functionality in Chrome, minor glitches in

First things first, I'm just diving into the world of javascript so please bear with my not-so-great code It seemed to work fine on Chrome but when I checked it on Firefox, everything went haywire Fiddle: jsfiddle.net/7NCcY/ <html> <head> ...

Tips for modifying my CSS LESS code without using the !important declaration

Here is the code I am working with: table { thead { th{ background-color: @grey-1; ... } } position: relative; &.option1 { thead { th { background - color: @grey-2; ... } } } &am ...

Generating Unique Random DIV IDs with JavaScript

Does anyone know of a JavaScript solution to generate unique random DIV IDs? I am currently using PHP for this purpose. <?php function getRandomWord($len = 10) { $word = array_merge(range('a', 'z'), range('A', &apos ...

Is it possible to customize the Menu hover effect in Element Plus and Vue?

Hello everyone, I'm a beginner with Vue, HTML, CSS, and Element Plus. I am trying to customize a Side Bar Menu with my own hover effect, but it doesn't seem to be working. Whenever I change the background color of the el-menu element, the hover e ...

What is the best way to position this dropdown menu component directly under a specific section of my navbar in a React application?

As I delved into creating a basic navbar and dropdown menu in React, I encountered a puzzling issue. I envisioned a section within the nav that would trigger a dropdown menu right below it upon hovering over it. Attempting to replicate this functionality b ...

Make sure that the contents of the div are all displayed on a single line

After searching for solutions here, I attempted the suggested code but unfortunately, it did not produce the desired outcome. My goal is to have all the alphabet letters appear on a single line. Kindly disregard my utilization of inline elements: <div ...

When Printed, the Text's Color in the Div Element Alters

I created a div with white text color, and now I'm facing an issue. By using CSS media queries, I set the text color to be white for printing purposes. @media print { .myid_print_duo_name { z-index: 2; position: absolute; ...

Modify the CSS of one div when hovering over a separate div

I've been working on a simple JavaScript drop-down menu, and it's been functioning correctly except for one issue. When I move the mouse out of the div that shows the drop-down menu, it loses its background color. I want the link to remain active ...

Adjust the height of images to be consistent

I'm currently working on creating a grid layout with 4 images in a row using DaisyUI card component. However, I've run into an issue where there is white space at the bottom of some images due to varying image heights. Is there a solution that wo ...