Assigning a Sass variable to an HSL value does not function properly when attempting to utilize it with HSLA

My Sass variable is mapped to an hsl value, but when I try to use it with hsla to add transparency, it doesn't work. This is what I'm trying to do:

$white:hsl(100, 100%, 100%);

.thing{
 color:hsla($white,.9);
}

When using gulp-sass to build my CSS, I encounter this error: "required parameter $lightness is missing in call to function hsla on line {line number} in {file's path}"

If I replace hsla with rgba, it works fine. However, I prefer to keep all my colors in hsl format. Is there a workaround for this issue or is it a problem specific to Sass?

Answer №1

The issue doesn't lie with SASS, as the feature simply isn't available. When consulting the official documentation, you'll notice that there are two variations of rgba(): one that requires individual parameters and another that accepts a Color object.

rgba($red, $green, $blue, $alpha)

rgba($color, $alpha)

If we consider hsla(), it exclusively accepts separate values.

hsla($hue, $saturation, $lightness, $alpha)

To accomplish your objective, you could follow this approach:

$white:hsl(100, 100%, 100%);

.thing{
 color: hsla(hue($white), saturation($white), lightness($white), .9);
}

Alternatively, if you wish to utilize the Color object in your function, you would need to create a custom function since it's not possible to overload functions; for example, hslac($color, $alpha)

@function hslac($color, $alpha) {
  @if(type-of($color) == "color") {
    @return hsla(hue($color), saturation($color), lightness($color), $alpha);
  }
  @else {
    @error "You didn't pass a color object";
  }
}

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

The Google calendar integration is working, but the appearance leaves much to

I embedded a Google calendar, but I'm having trouble centering it on the page without it overflowing onto the top menu. Can you help me fix this issue? If you'd like to see what I'm referring to, you can visit this link: ...

Align the ion content (or text or label) to the center vertically

I am striving to achieve a similar look as shown in the following images: https://i.sstatic.net/YFMay.png However, I am currently at this stage: https://i.sstatic.net/ZvpBV.png Please note that the first image showcases a bootstrap form, while the seco ...

The animation to alter the width of a div using jQuery is not functioning correctly

Hey everyone, I'm facing an issue with my variable (widthPercent) where I store a percentage, for example: 67.33%. When I try to change the width using jQuery animation, it doesn't work: $(this).animate({ width: widthPercent, }, 250 ...

Display a dynamic animation once the user switches to the tab

When a user opens the page in a new tab in the background, CSS animations are triggered before they switch to the tab. Is there a method to display the CSS animation only after the user selects the tab? ...

Is there a way for an element to automatically adjust its width to match another element?

I'm in the process of creating a new website... Check it out here: www.girlzwithmoustaches.com/home2 One feature I have is a social media icon banner that I designed to be part of the header... Below is the CSS code.. Now, I'm looking for a wa ...

Updating the content within a div following the submission of a contact form 7

I'm struggling with my contact form. I want the content of my contact form div to change after clicking submit on the form. I've been searching for a solution, but so far, no luck. Here is what I have: Form (div1) with input fields, acceptance c ...

Is there a way to decrease the speed of a text when hovering over it?

Is there a way to create a button that displays text before another text only on hover, with a delay? I've managed to achieve the effect but can't figure out how to slow it down. For example, notice how quickly the word "let's" appears when ...

Launching Firefox using Bootstrap on a Mac for media query breakpoints

I'm facing a major issue with my website. Running on Mac OS with Firefox version 29 (and previous versions). The site is responsive and built with Bootstrap. It functions perfectly on all browsers EXCEPT... On Mac using FF, right at the point where ...

Struggling to center a MatIcon within a MatButtonToggle component in an Angular project

I've been struggling to center the MatIcon in the MatButtonToggle, trying multiple methods without success. It may seem like a minor issue, but it's causing quite a bit of trouble for me. Can someone please guide me on how to make this adjustment ...

What is preventing Sublime Text from recognizing my pseudo classes as valid syntax?

I'm attempting to remove the underlines from all the links I've visited on a website. In my CSS file, I added nav li a:visited { text-decoration: none; } The word "visited" appears as white text in Sublime Text, indicating that the syntax ...

Incorporating SCSS into HTML files when they are situated at the same hierarchy

I have <h1 class='title home'> My Title </h1>, and to apply styles I can use the following CSS: .title { font-size: 1.95em; } .title .home { color: black; } While this method works, I a ...

Printing without sufficient paper will result in an incomplete printout

https://i.stack.imgur.com/jNlRr.jpg I am facing an issue with printing the last column "Potensi". The text in this column is not fully printed. How can I resolve this problem? I am using PHP. Thank you ...

Form validation in HTML is not showing up as expected

I'm new to HTML form validation and I'm currently trying to utilize browser defaults for this purpose. The form is designed to use a JQuery script to submit the data. Despite going through similar posts and updating my code, I am still facing iss ...

Creating a replica of Airbnb using Bootstrap 5: Transforming the search bar into a button

I am looking to implement a search bar button similar to the one on airbnb using bootstrap 5, like this example: https://i.sstatic.net/oIIzv.png Here is an example of HTML code that you can use: <button type="button" class="btn btn-ligh ...

Eliminate the outline of the pager row in an asp.net grid view

Within my grid view, I have applied a bottom border to all cells. However, this border is also appearing on the pager row, which is not desired. To address this issue, I attempted to use jQuery to remove the border, but it seems that my selector is incorre ...

Update the button text after it has been clicked

https://i.sstatic.net/QJALK.png In my code, I have a function that generates bootstrap rows, each containing an input field, textarea, and a remove button. As I call this function multiple times, I end up with several bootstrap rows. When clicking on the ...

Struggling with aligning images in the center of a square container

Currently revamping my photography website and working on a simple slider to showcase some of my photos. Struggling with aligning the images in divs with padding all around while keeping them centered. I want to replicate the look of my photos on Instagram ...

Is the z-index useless when the button is positioned behind divs and other elements?

I would like the "Kontakt" button to appear in the top right corner of the page, always on top of everything else. I have tried setting the z-index to z-index: 99999999999 !important;, but it doesn't seem to be working... On desktop, the button displ ...

What is the method for adding a before pseudo-element to my button element?

HTML & CSS Issue <button>Get Postion</button> Below is the CSS code for styling a button: button { padding: 1rem; background-color: red; color: wheat; border: 4px solid yellowgreen; position: relative; cursor: pointer; ...

Aligning input and submit fields perfectly in the same line

Struggling to get an input form and submit button to align perfectly in Firefox and Safari. Any advice? Here's the current CSS for the 'Keep in touch' widget on www.landedhouses.co.uk: form.mc4wp-form p{margin-left:0px !important; display: ...