国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Error encountered
Solution
Why?
Home Web Front-end CSS Tutorial When Sass and New CSS Features Collide

When Sass and New CSS Features Collide

Apr 04, 2025 am 10:21 AM

When Sass and New CSS Features Collide

CSS has recently added many cool features, such as custom properties and new functions. While these features can simplify our work, they can also create interesting interaction problems with preprocessors such as Sass.

This article will explore the problems I encountered, solutions, and why I still think Sass is essential.

Error encountered

If you have used the new min() and max() functions, you may encounter an error message like this when handling different units: "Incompatible units: vh and em".

This is because Sass has its own min() function and ignores CSS's min() function . Furthermore, Sass cannot perform any calculations using values ??that have no fixed relationship between two units.

For example, there is a fixed relationship between cm and in units, so Sass can calculate the result of min(20in, 50cm) and will not report an error when used in the code.

The same is true for other units. For example, there is a fixed relationship between angle units: 1turn, 1rad, or 1grad is always calculated as the same deg value. Similarly, 1s is always 1000ms, 1kHz is always 1000Hz, 1dppx is always 96dpi, and 1in is always 96px. That's why Sass can convert between them and mix them in calculations and functions (such as its own min() function).

However, when there is no fixed relationship between these units (such as the previous examples of em and vh units), problems arise.

It's not just a different unit. Trying to use calc() min() will also result in an error. If I try a code like calc(20em 7px) I get an error that " calc(20em 7px) is not a number for min ".

Another problem arises when we want to use the result of a CSS variable or mathematical CSS function such as calc() , min() or max() ) in a CSS filter (e.g. invert() ).

In this case, we will receive a prompt that "`$color: 'var(--p, 0.85)' is not a valid color for invert".

The same problem occurs grayscale() : " $color: 'calc(.2 var(--d, .3))' is not a valid color for grayscale".

opacity() also causes the same problem: " $color: 'var(--p, 0.8)' is not a valid color for opacity".

However, other filter functions—including sepia() , blur() , drop-shadow() , brightness() , contrast() , and hue-rotate() — all work properly with CSS variables!

As it turns out, what happened is similar to min() and max() problems. Sass does not have built-in sepia() , blur() , drop-shadow() , brightness() , contrast() , hue-rotate() functions, but it does have its own grayscale() , invert() and opacity() functions, and their first argument is $color value. Since it cannot find the parameter, an error is thrown.

For the same reason, we also have trouble when trying to use CSS variables that list at least two hsl() or hsla() values.

On the other hand, color: hsl(9, var(--sl, 95%, 65%)) is a fully valid CSS and works fine without Sass.

The exact same thing happens to rgb() and rgba() functions.

Also, if we import Compass and try to use CSS variables inside linear-gradient() or radial-gradient() , even if we use variables inside conic-gradient() (if the browser supports it), we will also get another error.

This is because Compass comes with linear-gradient() and radial-gradient() functions, but conic-gradient() function has never been added.

The problem in all these cases stems from Sass or Compass having functions of the same name, and assuming these are the functions we intend to use in our code.

Oops!

Solution

The trick here is to remember that Sass is case sensitive, but CSS is not case sensitive .

This means we can write Min(20em, 50vh) which Sass will not recognize as its own min() function. No error is thrown, it is still valid CSS and works as expected. Similarly, writing HSL() / HSLA() / RGB() / RGBA() or Invert() can avoid the problems we had before.

As for gradients, I usually prefer linear-Gradient() and radial-Gradient() because it's closer to the SVG version, but it works fine with at least one capital letter in it.

Why?

Almost every time I post any Sass-related tweets, I'll be warned that now that with CSS variables, Sass shouldn't be used anymore. I want to solve this problem and explain why I disagree.

First, while I found CSS variables to be very useful and used in almost every aspect over the last three years, it is important to note that they come with performance costs and it can be painful to use the current DevTools to track where errors appear in calc() calculation maze. I try to avoid overuse them so as not to get stuck in a situation where the shortcomings of using them outweigh the benefits.

Generally speaking, if it works like a constant, does not change element-by-element or state-by-state (in which case a custom attribute is definitely the best option), or reduces the number of compiled CSS (solves duplicate issues created by prefixes), then I'll use a Sass variable.

Second, variables have always been a small part of the reason I use Sass. When I started using Sass in late 2012, it was mainly used for loops, which is a feature we still don't have in CSS at the moment. While I have moved part of the loop to the HTML preprocessor (because it reduces the generated code and avoids having to modify both HTML and CSS later), I still use Sass loops in many cases, such as generating a list of values, stop lists within gradient functions, point lists within polygon functions, transform lists, and so on.

(The following content is consistent with the original text, omitting duplicate parts to avoid redundancy)

The above is the detailed content of When Sass and New CSS Features Collide. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How can I include CSS only on some pages? How can I include CSS only on some pages? Jun 11, 2025 am 12:01 AM

There are three ways to selectively include CSS on a specific page: 1. Inline CSS, suitable for pages that are not frequently accessed or require unique styles; 2. Load external CSS files using JavaScript conditions, suitable for situations where flexibility is required; 3. Containment on the server side, suitable for scenarios using server-side languages. This approach can optimize website performance and maintainability, but requires balance of modularity and performance.

Flexbox vs Grid: Understanding the Key Differences in CSS Layout Flexbox vs Grid: Understanding the Key Differences in CSS Layout Jun 10, 2025 am 12:03 AM

Flexboxisidealforone-dimensionallayouts,whileGridsuitstwo-dimensional,complexlayouts.UseFlexboxforaligningitemsinasingleaxisandGridforprecisecontroloverrowsandcolumnsinintricatedesigns.

Creating an Auto-Closing Notification With an HTML Popover Creating an Auto-Closing Notification With an HTML Popover Jun 10, 2025 am 09:45 AM

The HTML popover attribute transforms elements into top-layer elements that can be opened and closed with a button or JavaScript. Popovers can be dismissed a number of ways, but there is no option to auto-close them. Preethi has a technique you can u

What is 'render-blocking CSS'? What is 'render-blocking CSS'? Jun 24, 2025 am 12:42 AM

CSS blocks page rendering because browsers view inline and external CSS as key resources by default, especially with imported stylesheets, header large amounts of inline CSS, and unoptimized media query styles. 1. Extract critical CSS and embed it into HTML; 2. Delay loading non-critical CSS through JavaScript; 3. Use media attributes to optimize loading such as print styles; 4. Compress and merge CSS to reduce requests. It is recommended to use tools to extract key CSS, combine rel="preload" asynchronous loading, and use media delayed loading reasonably to avoid excessive splitting and complex script control.

How to use Lotties in Figma How to use Lotties in Figma Jun 14, 2025 am 10:17 AM

In the following tutorial, I will show you how to create Lottie animations in Figma. We'll use two colorful designs to exmplify how you can animate in Figma, and then I'll show you how to go from Figma to Lottie animations. All you need is a free Fig

Breaking Boundaries: Building a Tangram Puzzle With (S)CSS Breaking Boundaries: Building a Tangram Puzzle With (S)CSS Jun 13, 2025 am 11:33 AM

We put it to the test and it turns out Sass can replace JavaScript, at least when it comes to low-level logic and puzzle behavior. With nothing but maps, mixins, functions, and a whole lot of math, we managed to bring our Tangram puzzle to life, no J

External vs. Internal CSS: What's the Best Approach? External vs. Internal CSS: What's the Best Approach? Jun 20, 2025 am 12:45 AM

ThebestapproachforCSSdependsontheproject'sspecificneeds.Forlargerprojects,externalCSSisbetterduetomaintainabilityandreusability;forsmallerprojectsorsingle-pageapplications,internalCSSmightbemoresuitable.It'scrucialtobalanceprojectsize,performanceneed

Does my CSS must be on lower case? Does my CSS must be on lower case? Jun 19, 2025 am 12:29 AM

No,CSSdoesnothavetobeinlowercase.However,usinglowercaseisrecommendedfor:1)Consistencyandreadability,2)Avoidingerrorsinrelatedtechnologies,3)Potentialperformancebenefits,and4)Improvedcollaborationwithinteams.

See all articles