-
-
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
Media query mixins #13014
Media query mixins #13014
Conversation
Change 'it's' to 'it is' because for some reason it creates a parse error.
Escape ' with \ in less comments embedded within media query mixin because they cause parsing errors while running grunt.
media query mixin. Does not account for print media queries yet.
within the query.
@media (min-width: @screen-sm-min) { | ||
// Automatically set modal's width for larger viewports | ||
.screen-sm({ | ||
// Automatically set modal\'s width for larger viewports |
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.
Unnecessary backslash?
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.
@cvrebert I made a comment about that in the commit - but maybe it's worth adding a comment in the file itself. That is needed to escape the ' which for some reason causes a parsing error in that comment once you use a mixin with a ruleset. Other option would be to have bad punctuation and just drop the ' altogether.
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.
Let's report that upstream to the Less folks—we make extensive use of apostrophes 😁.
Nice, @mrmrs! I <3 refactoring. We should probably squash this into fewer commits before merging it. |
@cvrebert Thanks :) I <3 it too |
So, did anyone find/report the Less bug upstream? For the naming of the mixins, my suggestion would be |
Also, do we know whether this technique has a reasonable Sass translation (for bootstrap-sass)? |
Fixes #12974. |
SASS appears to have a similar function. @mixin screen-sm() {
@media (max-width: 812px) {
@content;
}
}
@mixin screen-md() {
@media (min-width: 813px) and (max-width: 1076px) {
@content;
}
}
@mixin screen-lg() {
@media (min-width: 1077px) {
@content
}
} Source: I've got to do some more testing but it should do the trick if you change to bootstraps spec. Edit: I've just done some testing, works like a charm using the following declarations: .no-display-small {
@include screen-sm() {
display:none;
}
}
@include screen-sm() {
.no-display-small {
display:none;
}
} Edit: I've just finalised it in bootstrap, and converted the existing LESS file to SASS. |
Please also see: #13619 I think your solution can work, personally i wonder if you should wrap media queries in a mixin this way. Media queries already have their own logical operators and preceding rules. Using this media queries mixins feels less intuitive for me now. If you have to combine two media queries for some reason, you will get:
But when testing this mixin strategy there seems noting wrong with the out put. I found:
will compile into:
The output of
|
You could well add another retina mixin, to apply to particular elements such as an image. @mixin screen-retina() {
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
@content
}
} or for more flexibility... @mixin screen-retina($pixel-ratio: 2) {
@media only screen and (-webkit-min-device-pixel-ratio: $pixel-ratio) {
@content
}
}
img.ratio-1 { @include screen-retina($pixel-ratio: 1); }
img.ratio-2 { @include screen-retina(); } Retina displays and retina CSS is in fact trending and it would be wise to include the ability to do this out of the box. I would just create an extra less/scss file to include custom mixins but for the greater good we will eventually need this. |
I've duplicated the changes in this issue log in bootstrap sass and requested a pull. |
@fubarhouse I believe the Sass port is mostly autogenerated, so they might need a patch to their Less=>SCSS conversion script instead of a patch to the SCSS directly. |
Punting to v4 per the issue. |
This covers the majority of media queries present in bootstrap except for
Print queries will be super easy if we just add another mixin.
For the second and third cases - ideally you could override these defaults without having to add new mixins. Still looking into that.