如何在 CSS 3 媒体查询中使用 SASS 逻辑
我通过指南针框架和蓝图/网格依赖项使用 saas。我希望能够使用媒体查询设置列的宽度,如下所示:
// /src/partials/_base.scss
$blueprint-grid-columns: 18;
@media screen and (max-width: 1024px){
// If screen res is 1024 or lower, then set grid width to 46px
$blueprint-grid-width: 46px;
}
@media screen and (max-width: 1280px){
$blueprint-grid-width: 50px;
}
@media screen and (max-width: 1600px){
$blueprint-grid-width: 76px;
}
$blueprint-grid-margin: 8px;
这会编译为 /stylesheets/screen.css:
@media screen and (max-width: 1024px) {}
@media screen and (max-width: 1280px) {}
@media screen and (max-width: 1600px) {}
但 screen.css 其余部分中的值不会相应设置。我想这是有道理的,因为 $blueprint-grid-width 变量是在编译时读取的,而不是运行时读取的。
有没有办法通过使用媒体查询来获取屏幕分辨率来输出具有不同网格宽度的布局?
相关github问题:
https://github.com/chriseppstein/compass/issues/302
I'm using saas via the compass framework and the blueprint/grid dependency. I want to be able to set the width of a column using a media query, like so:
// /src/partials/_base.scss
$blueprint-grid-columns: 18;
@media screen and (max-width: 1024px){
// If screen res is 1024 or lower, then set grid width to 46px
$blueprint-grid-width: 46px;
}
@media screen and (max-width: 1280px){
$blueprint-grid-width: 50px;
}
@media screen and (max-width: 1600px){
$blueprint-grid-width: 76px;
}
$blueprint-grid-margin: 8px;
This compiles to in /stylesheets/screen.css:
@media screen and (max-width: 1024px) {}
@media screen and (max-width: 1280px) {}
@media screen and (max-width: 1600px) {}
But the values in the rest of screen.css are not set accordingly. I guess that makes sense, since the $blueprint-grid-width variable is read at compile time, not run time.
Is there a way to output a layout with different grid widths by using a media query to get screen resolution?
Related github issue:
https://github.com/chriseppstein/compass/issues/302
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 SASS 中的一个错误。从版本 3.1.0 开始已修复:
http://sass-lang .com/docs/yardoc/file.SASS_CHANGELOG.html#310
This was a bug in SASS. It's been fixed as of version 3.1.0:
http://sass-lang.com/docs/yardoc/file.SASS_CHANGELOG.html#310
我正在尝试弄清楚同样的事情,但似乎没有一个好的方法可以让它按照我想要的方式工作。就像你说的,变量是在编译时设置的,而不是运行时设置的,所以很难计算。我认为你可以做这样的事情:
但是你必须为你想要运行的每个媒体查询做同样的、强力的蓝图重置。
I'm trying to figure out the same thing but there doesn't seem to be a good way to get this working the way I want it to. Like you said, the variables get set at compile time, not runtime so it's hard to figure. I think you could do something like this:
But then you'd have to do this same, brute force kind of reset of Blueprint for every media query you want to run.