Why is the greater-than operator not functioning correctly in the @if statement of this mixin?

.container {
  --random: 200px;

  @mixin test() {
    @if (var(--random) > 500px) {
      color: orange;
    }
  }

  @include test();
}

My objective is to apply the style color: orange; to .container if the variable exceeds 500px.

P.S. I was unsure about how to create a code snippet to demonstrate this issue. Do you have any suggestions for a website where I can generate small SASS snippets?

Answer №1

One interesting point brought up by Dai in the comments is the distinction between SASS variables and custom properties (also known as CSS variables). For your specific situation, it would be best to utilize a SASS variable:

.container {
  $dynamicSize: 200px;

  @mixin checkSize() {
    @if ($dynamicSize > 500px) {
      color: orange;
    }
  }

  @include checkSize();
}

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

Learn the effective way to customize the primary button text color in Bootstrap 4 using SCSS styling

Looking to customize the .btn-primary text color. I attempted to modify the background color in _variables.scss by adding the following line: $primary: #a1c1b6; However, I was unable to change the text color despite trying various options. // not working ...

Tips for Aligning Several Images Horizontally in an Article

Does anyone know how to center pictures in an article horizontally? I've tried various techniques without success. If it would be helpful, I can share the CSS I currently have. However, I am open to starting from scratch with the CSS as well since I ...

Leverage the power of HTML5 localstorage in order to maintain the toggle state of jQuery even

After discovering the HTML5 "localstorage" function, I decided to try implementing it in combination with jQuery toggle to keep a div in its most recent state even when the page is refreshed. It seems like a more modern alternative to using cookies. Howeve ...

Using box-shadow with table rows

I am encountering an issue trying to add a box-shadow to tr elements within a table. The problem arises when the box-shadow does not display unless all the tr elements are set with a display property of block, as suggested in this workaround: Box Shadow in ...

Initiating a sequential CSS launch using JQuery

Looking for a way to create a dynamic animation using JQuery and .css? This code will rotate letters left, then right, then left, then right again while moving up. $('.envelope').click(function() { $(this).find('.list') .animat ...

Establish a new <section> to serve as a distinct webpage

I have a question about creating multiple <section> elements on a page. I am looking to build an HTML document with several <section> tags, as outlined below. <html> <head> </head> <body> <sectio ...

Customizing CSS based on URL or parent-child relationship in WordPress

I'm having trouble finding a solution for what seems like a simple issue... Currently, my header has a border-bottom and I'd like to change the color of this border based on the section the user is in. For example, consider these parent pages: ...

What methods can be utilized to create a versatile ratings widget using LESS instead of traditional CSS?

Recently, I stumbled upon a versatile one-image rating widget created with SASS by the team at AirBnB. I am interested in replicating something similar using LESS. While I could manually write out the CSS, I prefer to generate it dynamically with LESS. My ...

Flexbox - Consistent height image columns

I'm working on a basic flexbox layout that looks something like this: html,body { margin:0; padding:0; } body { height:100%; width:100%; } .panel-grid { -webkit-align-items: flex-start; ...

Placement of text is incorrect on certain react cards

I have an application that retrieves videos and generates a card for each video, displaying the video title, creator, link, download option, views, and upload date on each card. Fetching and displaying these elements works well, for the most part. However ...

Is there a way to display a div element just once in AngularJS?

I only want to print the div once and prevent it from printing again. $scope.printDiv = function(divName) { var printContents = document.getElementById(divName).innerHTML; var popupWin = window.open('', '_blank', 'width=300, ...

When attempting to change the text in the textarea by selecting a different option from the dropdown list, the text is not updating

I am facing an issue with three multi-select dropdown lists. When a user selects options from these lists and then presses the submit button, the selected text should display in a textarea. However, if the user manually changes some text in the textarea ...

Invisible and Unrestricted automatic playback

Why is auto play muted in both Firefox and Chrome? How can we code it so that browsers don't block it? Here's the code I'm using: <audio id="audio1" src="https://notificationsounds.com/storage/sounds/file-sounds-1217-relax ...

Move the Bootstrap modal footer button to the left side

I am trying to align the cancel button to the left of the footer and keep the close and save buttons on the right side at all times. Even after adding the float:left property to the cancel button, it did not solve my issue. I would appreciate any solution ...

Tips for modifying the appearance of this input document

Hey there, I have this input element created in React: <span className="btn-file" type='button'> <div style={{display:'flex',justifyContent:'space-around'}}> <span style ...

CSS3 Internet Explorer 6 problem

In Firefox, the following code works fine as I am using CSS3 to create rounded borders. Can someone please advise on what changes are needed to achieve the same result in IE6? Here is the code: <html> <head> <style type="text/css"> bac ...

Challenges with resizing floating divs

As a beginner in Web Development, I am tasked with creating a web portfolio for an assignment. In my design layout, I have a navigation bar in a div floated left, and a content div floated right serving as an about me section containing paragraphs and lis ...

Instructions for accessing the contents of a file that has been uploaded via the "Input Type" field in an HTML form

I have a basic HTML form with an upload field that allows users to select and upload local files. After uploading a file, the path displayed is C:/fakepath/filename.xls. I understand that this is due to browser security measures preventing direct access t ...

Expanding an item to fill the entire width within a Bootstrap navigation bar

Here is the layout of the navigation bar in my current web application project: [ Brand [button] [button] [----- input field -----] ----- empty space ----- [button] ] This is a simplified version of the code I am working with: <div class="container-f ...

I'm looking to display a text box on my website specifically for users using IE11

I'm following up on my previous post that was put on hold. I encountered some issues with my website in IE11, which are now resolved. However, I want to implement a code snippet that will display a text box if any similar problems arise in the future ...