I think you did not understand how works SASS / Compass and media queries.
Variables are transformed by the compiler before being sent to the client as opposed to media queries that are interpreted by the browser's CSS engine as well as conventional selectors (id, class, tag)
The compiler does not interpret the media query as a condition, simply because at the time of compilation, the screen size is not defined, and especially because it is not his job.
Here is a simplified version of what happens:
- 1
$arrow-size: 30px;
"ok, I set a new variable arrow-size
to 30px
"
- 3
@media only screen and (max-width: 449px) {
"ok, a new selector...
syntax is correct, I'll look later if the brace is closed."
- 4
$arrow-size: 15px;
"ok, I set the arrow-size
variable to 15px
"
- 5
}
"ok, brace is closed"
- ...
- 13
border-bottom: $arrow-size solid white;
"A new css rule, syntax ok... oh, I have to replace a variable ! How much for $arrow-size
? Oh yes, 15px
, I change it."
In result, the compiled CSS file will be :
screen.css
@media only screen and (max-width: 449px) {
}
div.selector {
height: 0px;
width: 0px;
position: absolute;
bottom: 0px;
left: 50%;
border-bottom: 15px solid white;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}
you can also put your media queries into selectors :
$arrow-normal-size: 30px;
$arrow-small-size: 15px;
div.selector {
height: 0px;
width: 0px;
position: absolute;
bottom: 0px;
left: 50%;
border-bottom: solid white;
border-left: solid transparent;
border-right: solid transparent;
border-width: $arrow-normal-size;
@media only screen and (max-width: 449px) {
border-width: $arrow-small-size;
}
}
or use a mixin :
a little bit useless in this specific case
@mixin responsive-border($max-screen-width, $border-width){
@media only screen and (max-width: #{$max-screen-width}) {
border-width: $border-width;
}
}
div.selector {
height: 0px;
width: 0px;
position: absolute;
bottom: 0px;
left: 50%;
border-bottom: solid white;
border-left: solid transparent;
border-right: solid transparent;
border-width: 30px;
@include responsive-border(449px,15px);
}