在CSS 3媒体查询中使用Sass变量我试图将Sass变量的使用与@media查询结合起来,如下所示:$base_width:1160px;
@media screen and (max-width: 1170px) {$base_width: 960px;}
@media screen and (min-width: 1171px) {$base_width: 1160px;}$base_width然后在样式表宽度基于百分比的测量中的不同点定义,以生成流体布局。当我这样做时,似乎正确地识别了变量,但是媒体查询的条件却没有被正确识别。例如,上面的代码生成一个1160 px布局,而不考虑屏幕宽度。如果我翻动一下@media语句,如下所示:@media screen and (min-width: 1171px) {$base_width: 1160px;}
@media screen and (max-width: 1170px) {$base_width: 960px;}它产生一个960px的布局,同样不管屏幕的宽度。还请注意,如果我删除了$base_width: 1160px;它返回一个未定义变量的错误。知道我错过了什么吗?
3 回答
偶然的你
TA贡献1841条经验 获得超3个赞
@media screen and (max-width: 1170px)
$base_width
@media screen and (max-width: 1170px) $base_width: 960px // you need to indent it to (re)set it just within this media-query // now you copy all the css rules/properties that contain or are relative to $base_width e.g. #wrapper width: $base_width ... @media screen and (min-width: 1171px) $base_width: 1160px #wrapper width: $base_width ...
@media screen and (min-width: 1171px) +base_width_changes(1160px) #width-1171-specific-element // additional specific changes, that aren't in the mixin display: block
=base_width_changes($base_width) #wrapper width: $base_width
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
@mixin styling($base-width) { // your SCSS here, e.g. #Contents { width: $base-width; } } @media screen and (max-width: 1170px) { @include styling($base-width: 960px); } @media screen and (min-width: 1171px) { @include styling($base-width: 1160px); }
慕桂英546537
TA贡献1848条经验 获得超10个赞
@import
@media screen and (max-width: 1170px) { $base_width: 960px; @import "responsive_elements"; } @media screen and (min-width: 1171px) { $base_width: 1160px; @import "responsive_elements"; }
- 3 回答
- 0 关注
- 610 浏览
添加回答
举报
0/150
提交
取消