-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Unitless breakpoints #27190
Unitless breakpoints #27190
Conversation
If I want to customise the breakpoints using `em`, I get compatibility errors. It is good practice to set breakpoints in `em` instead of `px` when users use browser scaling. See https://zellwk.com/blog/media-query-units/#concluding-the-experiments for more information why someone would like to do this. Only Safari users can get annoyed: https://adamwathan.me/dont-use-em-for-media-queries/ In any case, using a unitless number at line 42 would be very convenient.
While it seems like this may be a bad option according to Adam's article, it makes sense to me to make this change, and allow the user to choose whether or not the Safari bug is an issue for them. I was not familiar with SCSS math, so I did a little digging into whether this is valid, and it turns out, it works! If you use a unitless value with a value with a unit, the unit is preserved. However, mixing units will result in an error. .style {
height: 500em - 100;
width: 500px - 100;
} compiles to .style {
height: 400em;
width: 400px;
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @johanlef thanks a lot for your contribution.
There has been a lot of discussion around this issue, among them #22006, #25632, #19619, #25166, and others related to why we are using px
s instead of rem
s or em
s
Personally, I think we should look into moving to relative units, but at this point, it'd be a breaking change for v4.
Having said that I think this is a good discussion point for v5.
Okay, I understand moving to other units will be a breaking change. @andresgalante Going from |
Correct me if I'm wrong, but I don't believe this would be a breaking change in v4. As I showed in my first comment, when doing math in SCSS, if one of the values is unitless, the other units will be preserved. By merging this PR, all existing code would work as is, and it would allow people who choose to use |
@andresgalante My proposal is about removing the unit, not changing to another one. When the unit is removed, the original unit is preserved, so this change would not cause any issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine? Not sold on em-based media queries yet as we've gone back and forth on that a lot, but this seems fine.
Just so that we are safe, is this backwards compatible? |
@XhmikosR I believe so—this is Sass math, and previously we required folks to use pixels only for media queries. This opens it up so others can use |
If I want to customise the breakpoints using
em
, I get compatibility errors.It is good practice to set breakpoints in
em
instead ofpx
when users change font size in their browser. See https://zellwk.com/blog/media-query-units/#concluding-the-experiments for more information why someone would like to do this. Only Safari users could get annoyed: https://adamwathan.me/dont-use-em-for-media-queries/In any case, using a unitless number at line 42 would be very convenient.