Media query expected ошибка

I’m trying to standardize the sizes of the devices on my scss, based on this:

/** Extra small devices (phones, 600px and down) */
$extra-small-evices: "screen and (max-width: 600px)",
/** Small devices (portrait tablets and large phones, 601px to 768px) */
$small-devices = 'screen and (min-width: 601px) and (max-width: 768px)',
/** Medium devices (landscape tablets, 769px to 991px) */
$medium-devices = 'screen and (min-width: 769px) and (max-width: 991px)',
/** Large devices (laptops/desktops, 992px to 1200px) */
$large-devices = 'screen and (min-width: 992px) and (max-width: 1200px)',
/** Extra large devices (large laptops and desktops, 1201px and up) */
$extra-large-devices = 'screen and (min-width: 1201px)'

After this, less say that I want to create a media query which the target is the small devices and medium devices:

@media $small-devices,
@media $medium-devices{
   ....
}

But I’m getting the following error on the @media $small-devices, line:

[scss] media query expected

Environment: Visual studio code, nodejs, angular 6, gulp,

Any one knows how no solve this?

I’m trying to standardize the sizes of the devices on my scss, based on this:

/** Extra small devices (phones, 600px and down) */
$extra-small-evices: "screen and (max-width: 600px)",
/** Small devices (portrait tablets and large phones, 601px to 768px) */
$small-devices = 'screen and (min-width: 601px) and (max-width: 768px)',
/** Medium devices (landscape tablets, 769px to 991px) */
$medium-devices = 'screen and (min-width: 769px) and (max-width: 991px)',
/** Large devices (laptops/desktops, 992px to 1200px) */
$large-devices = 'screen and (min-width: 992px) and (max-width: 1200px)',
/** Extra large devices (large laptops and desktops, 1201px and up) */
$extra-large-devices = 'screen and (min-width: 1201px)'

After this, less say that I want to create a media query which the target is the small devices and medium devices:

@media $small-devices,
@media $medium-devices{
   ....
}

But I’m getting the following error on the @media $small-devices, line:

[scss] media query expected

Environment: Visual studio code, nodejs, angular 6, gulp,

Any one knows how no solve this?

Вы должны сообщить SASS, что ваша строка не должна заключаться в кавычки и обрабатываться как обычный CSS:

@media #{unquote($small-devices)}{
    // Your output here
}

Вы все еще можете использовать несколько таких:

@media #{unquote($small-devices)},
       #{unquote($extra-small-devices)}{
    // Your output here
}

Но, возможно, для стиля и элегантности вы можете подумать о создании миксина, который просто берет все строки, а затем создает медиа-запрос как таковой:

@mixin media( $selectors... ){

    $selector: '';

    @each $s in $selectors {

        @if $selector == '' { $selector: $s; }
        @else { $selector: $selector + ', ' + $s; }

    }

    @media #{unquote($selector)}{

        @content;

    }

}

А затем используйте его как таковое:

@include media( $extra-small-devices, $extra-large-devices ){

    ...

}

И вывод будет:

@media screen and (max-width: 600px), screen and (min-width: 1201px) {

    ...

}

Я нашел способ сделать это, чтобы работать без необходимости указывать, если заявление для каждого типа носителя.

@mixin breakpoints($min-width, $max-width, $media-type: false) {
  @if $media-type {
    @media #{$media-type} and (min-width: $min-width) and (max-width: $max-width) {
      @content;
    }
  } @else {
    @media all and (min-width: $min-width) and (max-width: $max-width) {
      @content;
    }
  }
}

ключ был в #{$media-type}. сейчас все работает, но я не знаю, насколько правильное мое решение.

Теперь я могу позвонить в Mixin с

@include breakpoints(400, 600, only screen)

а также

@include breakpoints(400, 600, 'only screen')

а также

@include breakpoints(400, 600)

который вернет ключевое слово all

@alastc

Running Sass on an imported file that includes this line:

Sass reports:
error media-queries.sass (Line 8: Invalid CSS after «screen «: expected media query list, was «{«)

I’m pretty sure that’s valid though, you don’t have to include size or other terms, like the second example here: http://www.w3.org/TR/css3-mediaqueries/

@Snugug

I’m not sure what version of Sass you’re running, but using both Sass 3.2.12 and Sass 3.3.rc.2, the following compiles absolutely fine:

@media screen {
  .foo {
    content: bar;
  }
}

@alastc

3.2.12, but perhaps it makes a difference that it is in an import? I moved my media queres into another file (media-queries.sass) and imported that into the main file. Then I get the errors.

I took the error message too literally though, it doesn’t matter whether there are ‘and’ conditions, it seems to matter they are in an import though.

@Snugug

Having them in an imported file should not make a difference and does not make a difference when tested. My suggestion is to build a reduced example and add back in code until you find your error; I’m willing to bet you have a syntax error somewhere, not that @media screen doesn’t work.

@nex3

I’m closing this, but I’ll re-open if you can provide a file or files that can consistently reproduce the error.

@alastc

Has the nature of ‘watch’ changed when I wasn’t looking? A sass file of just this:

Then:
# sass —watch test.sass:test.css

Gives me:

error test.sass (Line 2: Invalid CSS after «0»: expected expression (e.g. 1px, bold), was «;»)

Is there a forum somewhere? This is really odd, it is CSS that’s working fine in the full SASS stylesheet. Need somewhere to ask questions…

@nex3

That’s SCSS syntax, but your file uses the extension .sass, so Sass is trying to interpret it as the indented syntax and failing. Could that also be your problem with the media query?

@alastc

Ah, yes, that’s why everything seems to be wrong when I import that.

Sorry, I have never used the indented syntax, so I have no idea why I put .sass on that!

Понравилась статья? Поделить с друзьями:
  • Media led 1 ошибка
  • Media jam ошибка принтера
  • Media get ошибка загрузки
  • Media feature pack windows 10 ошибка 0x80004005
  • Media encoder ошибка компиляции