Breakpoint Sass: Or Queries for Multiple Breakpoints

前提是你 提交于 2019-12-07 07:38:44

问题


I have a few breakpoints set:

$breakpoint-tiny : 0 767px;
$breakpoint-small : 768px 991px ;
$breakpoint-medium : 992px 1229px;
$breakpoint-large : 1230px;

I saw in the breakpoint docs

You can also write OR media queries, allowing you to write multiple different basic or compound media queries and have them apply if any of the sets of queries match.

What I'd like to do is use these or queries to target multiple breakpoints when needed in my code. For example:

@include breakpoint($breakpoint-medium, $breakpoint-large){
   .mobile-navigation{display: none;}
}

Is this possible?


回答1:


You should pass one parameter (a list), instead of two.

Try this.

@include breakpoint(($breakpoint-medium, $breakpoint-large)) {
    .mobile-navigation{display: none;}
}

I've wrapped your comma separated variables with parentheses. Now Sass will see them as a one list, instead of two parameters.




回答2:


There are no OR queries in compass breakpoints, in particular @include breakpoint(($breakpoint-medium, $breakpoint-large)) fails with:

WARNING: Responsive contexts are not available for or queries as which query to use is ambiguous. Please only use single context queries. Default context is used.

You can use OR queries with the plain css @media rules if you really need it.

The right solution is to not specify a max width for your breakpoints, only the min width. Then start writing your sites without breakpoints ("mobile first"). If layout needs to change at a certain width you @include breakpoint($brk) and change the layout for all widths larger than $brk. That way you never have to specify a list of intervals that the media query applies to.



来源:https://stackoverflow.com/questions/23350039/breakpoint-sass-or-queries-for-multiple-breakpoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!