What could be causing the @each statement in SASS to not function properly in Next.js?

I am struggling with my SCSS files and color scheme

colors.scss

@import './variables';

$colors: (
  p: $color-primary,
  s: $color-secondary,
  t: $color-tertiary,
  q: $color-quartary,
);

@each $name, $hsl in $colors {
  .c-#{name} {
    color: $hsl;
  }
  .bg-#{name} {
    background: $hsl;
  }
}

Alongside the file containing variables

variables.scss

$color-primary: hsl(113, 99%, 53%);
$color-secondary: hsl(0, 7%, 19%);
$color-tertiary: hsl(0, 7%, 78%);
$color-quartary: hsl(2, 87%, 48%);

Lastly

main.scss

@import './variables';
@import './colors';

body {
  color: $color-tertiary;
  background-color: $color-secondary;
}

My question is why I cannot utilize the classes created within the @each loop as expected like c-p, bg-p, c-s, etc.

If I manually define a class like c-p

.c-p {
  color: $color-primary;
}

It works regardless of where it's defined in _colors.scss or main.scss, either before or after the @each statement. Why is that?

Answer №1

It seems that your current loop is generating CSS classes such as .bg-name and .c-name because you are using the string name instead of the variable $name. Consider updating your code to:

@each $name, $hsl in $colors {
  .c-#{$name} {
    color: $hsl;
  }
  .bg-#{$name} {
    background: $hsl;
  }
}

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

Achieving Right Alignment of SVG Next to an <h4> in Bootstrap 5

I'm encountering an issue where I am attempting to align an SVG icon to the right of an H4 element and center it vertically using Bootstrap 5, but it's not working as intended. <div class="container-fluid"> <div class="r ...

Applying the jqtransform plugin to all forms except for one

We've implemented the jQuery jqtransform plugin to enhance the appearance of our website's forms. However, there is one particular form that we'd like to exclude from this transformation. I made adjustments to the script that applies jqtrans ...

Issue with the pluses and minuses in the Bootstrap accordion

Can someone explain why the panel-header displays all "-" instead of "+"? When I click on the panel, it changes all "-" to "+". This happens consistently, not just the first time the page loads. My CSS code: .panel-heading a:after { font-family: &ap ...

The dropdown arrow icon fails to display downward direction when double-clicked

I'm working on a select dropdown that resembles a material UI dropdown. I've added icons for an arrow up and arrow down to indicate the state of the dropdown. The aim is to show the arrow up when the dropdown is open and switch to the arrow down ...

`Div Elements Overlapping`

Lately, I have been working on my personal portfolio and I encountered an issue with the contact form overlapping the footer. Can anyone provide some guidance on how to resolve this? Any help is greatly appreciated. https://i.stack.imgur.com/neIbs.gif ...

The issue of margin error and vertical alignment on pseudo-elements

Here's the HTML code I am working with: <article> <picture> <img src="a.png"> </picture> </article This particular HTML code is used throughout my page, where the image has a varying width. The goal is to c ...

The issue with Bootstrap Vue is that it fails to render the CSS properly when utilizing cards

Recently, I delved into the world of Bootstrap Vue and wrote the code snippet below: <template> <div> <div> <b-card-group> <b-card border-variant="dark" header="Dark" align="center"> &l ...

Increase the size of the parent div as the height of the position:absolute child div grows

I am facing an issue with a parent div and its 2 child divs. <div id="parent"> <div class="child1 col-2"></div> <div class="child2 col-10"></div> </div> The child1 div has absolute positioning a ...

Bootstrap gallery with images that resize proportionally

Attempting to create something simple, but currently unsure how to proceed. A few months ago, I had a concept in mind, but unfortunately lost the files and now feeling stuck. Using Bootstrap to construct a gallery with two different image sizes: 1920x1200 ...

Unable to adjust the dimensions of a Mailchimp input field

Having some trouble customizing my Mailchimp form a bit and could use some assistance. Snippet of the code: <!-- Begin MailChimp Signup Form --> <link href="//cdn-images.mailchimp.com/embedcode/horizontal-slim-10_7.css" rel="stylesheet" type=" ...

Ensure that divs remain in a static position within the dialog box

Within the jQueryUI dialog, I have gray boxes at the top and bottom of the visible area represented by the .nav elements. I want these gray boxes to stay fixed in their position even when scrolling within the dialog. Despite setting position: absolute, the ...

Mastering Fluent UI Web: Adjusting the border radius of a TextField component

I am in the process of creating a custom user input control that includes a TextField, a Dropdown, and a Button. To ensure that the TextField and Dropdown appear as a cohesive unit rather than two separate elements, I attempted to use two specific styles ...

Styling User Accounts in Meteor: Tips and Tricks

Utilizing meteor-useraccounts to manage user accounts, including the integration of useraccounts:bootstrap. The boilerplate I'm using is directly from the repository. The challenge: I am confused about where to insert my own HTML/CSS. Here is my con ...

What could be causing my dropdown menu code to malfunction?

Having trouble with the drop-down menu! I used "display: none;" in CSS to hide the list, but I'm not sure if it's the best way. This idea was borrowed from a Codecademy project. I know there may be some cringe-worthy code here, but please bear w ...

The following command "next build && next export" creates two separate folders for building the project

Whenever I run next build && next export to build my project for production, it generates two folders - .next and out. I feel like the out folder is sufficient for my project. Is it possible to avoid creating the .next folder altogether? If so, h ...

Solution for resolving AMP Error related to the Imply script tag within a nextjs application

Tag located outside the document head, which should only be a direct child of the document head. Error: Invalid attribute: data-amp-bind Fix: Make sure you are using only allowed attributes for AMP components. If you are using custom attributes, they sho ...

What is the best way to pass postData to the layout in Next.js?

How can I pass the postData to a layout component? In this scenario, I would like my ArticleStyle2 layout to receive the postData and use it to populate itself with the data. I'm not certain if this is the recommended approach in nextJs and react sinc ...

Picture remains unchanged in Chrome

I'm struggling to understand why my images do not resize when I shrink or resize my Chrome window. Can someone help me out with an explanation? I've been trying for some time now but still can't seem to crack it, and I haven't found the ...

Ways to stop Next JS 13 from automatically preloading pages

While using my app that is connected to Firebase, I have noticed that each time a page loads, my usage count exceeds due to the Next JS preloading feature. This unexpected increase in cost is concerning. How can I prevent Next JS 13 from preloading? I susp ...

What's the deal with session-based middleware?

In the way my architecture is structured: I have Next.js (browser) connecting to Next.js (middleware), which then talks to a 3rd-party API. The middleware has the task of managing and storing users' access tokens. Currently, everything is functioni ...