New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Omit units for zero values #649
Comments
+1 for that, would look cleaner also. |
When would the unit be stripped? For math in mixins and functions a zero with units is sometimes necessary. |
In what case does the unit of a zero matter in a multiplication/addition/else ? |
Just to slightly correct the premise of this suggestion, it's actually incorrect to say that zero absolutely doesn't need units inside CSS. For instance, resolution media queries require units even if the value is zero. On Feb 17, 2013, at 11:40 AM, Maxime Fabre notifications@github.com wrote:
|
As snugug says, $var / ($var * 0) +1 depends on zero with a unit. |
Yeah but as I understood it the initial proposal was to remove units from the final CSS, not in the middle of the SASS calculus. |
The idea was for the end CSS, so maybe adding it to the list of optimizations in the output style. Similar to how the :compressed will optimize properties to their smallest form. |
I thought that was probably the idea, just wanted clarification. |
That's fine as long as its understood that not all of CSS is cool with unit less 0s now and potentially in the future. I'd be curious how much is actually saved by this pseudo-optimization especially when you can currently just write 0 w/o units. (i.e. how often is a 0 with a unit generated that you would want it stripped out) On Feb 17, 2013, at 1:52 PM, Rob Wierzbowski notifications@github.com wrote:
|
Sass doesn't have enough context information when rendering a number to a string to determine if it's safe to leave off the unit. |
I verified with @tabatkins that it is safe for Sass to omit the unit for lengths when the value is 0. This is true for all properties. However, there is one known ambiguity if you have a list of values for the We should consider adding support for this. Re-opening. |
I'm very skeptical of any behavior here that relies on knowledge of CSS's current ambiguities between numbers and lengths. I don't want to have to maintain a list of workarounds for properties like There are some types of optimizations that are better for a post-processor with encyclopedic knowledge of CSS properties to do, and I think this may be one of them. |
I created a minimal working example which demonstrates that omitting the unit for lengths when the value is 0 can affect how the content is displayed. This happens across browsers: |
|
@tabatkins yes technically you are right but it's still relevant in this discussion and according to https://github.com/CSSLint/csslint/wiki/Disallow-units-for-zero-values, "the value of 0 works without specifying units in all situations where numbers with length units or percentages are allowed," which isn't true for percentages. |
Ah, that CSSLint line is wrong, then. |
@tabatkins and the CSSLint warning that's generated as well. :P |
I'm moving this issue to the new Ruby Sass repository because it's specific to Ruby Sass's implementation. Once it's there, I'm going to close it as "on ice" because Ruby Sass is deprecated and no additional features are planned for it. |
I discovered that there apparently is a difference between 0 with and without a unit. It's connected with the I assume there should be kind of a setting to disable removing units for 0s. |
@mkasprz Good catch. Since we aren't aware which property a number is being serialized for, we shouldn't remove units ever. |
@arthurio When I compile that example with Dart Sass 1.44.0 I get |
@nex3 Good to know, I'll do some digging and report back. Thanks for letting me know 👍🏻 |
@nex3 Sorry I forgot to report back, the issue was indeed further down the pipeline... Our minifier is the one which was replacing |
This was incorrectly posted in the Compass queue, re-posting here on behalf of @nschonni as I see value in unit omission for zero values.
https://github.com/stubbornella/csslint/wiki/Disallow-units-for-zero-values
The text was updated successfully, but these errors were encountered: