在@media规则中包含“all”的目的是什么?

时间:2016-02-23 01:30:09

标签: css

所以你看到很多代码示例都像

那样
public static void main(String[] args) throws Exception {
    // Create a File instance
    java.io.File file = new java.io.File("samplefile.txt");

    // Create a Scanner for the file
    Scanner input = new Scanner(file);

    // Create the Content String        
    String fileContent = "";

    // Read data from a file
    while (input.hasNext()) {
        fileContent += input.next() + " ";
    }
    // Close the file
    input.close();

    //Split the string into a character array
    char[] charArr = fileContent.toCharArray();

    //loop through every character to find the vowels
    int counter = 0;
    for(char c : charArr)
    {
          if(c == 'a')
               counter_a++;
          if(c == 'e')
               counter_b++;
          if(c == 'i')
               counter_i++;
          if(c == 'o')
               counter_o++;
          if(c == 'u')
               counter_u++;
    }

    //number of vowels
    System.out.println("Number of Vowels: " + (counter_a+counter_e+counter_o+counter_i+counter_u));
    System.out.println(counter_a);
    System.out.println(counter_e);
    System.out.println(counter_i);
    System.out.println(counter_o);
    System.out.println(counter_u);

    }}

现在afaik,关键字“all”和“screen”以及其他一些用于选择适用的设备类型,并且该行应该提供布尔输出。

由于“all”适用于每个设备,人们可以想象它总是1和(1& x)总是等于x所以“all and”应该没有任何区别。

我试过了

@media all and (max-width:640px) {
    div {
        background-color:red;
    }
}

至少我的浏览器同意了。还有什么我应该知道的吗?

2 个答案:

答案 0 :(得分:1)

请参阅规范:https://www.w3.org/TR/css3-mediaqueries/

  

'print'和'screen'媒体类型在HTML4中定义。 HTML4中媒体类型的完整列表是:'aural','braille','掌上','print','projection','screen','tty','tv'。 CSS2定义了相同的列表,弃用了'aural'并添加了'embossed'和'speech'。此外,'all'用于表示样式表适用于所有媒体类型

     

...

     

为适用于所有媒体类型的媒体查询提供简写语法;可以省略关键字'all'(以及尾随'和')。即如果未明确指定媒体类型,则为“全部”。

/* I.e. these are identical: */

@media all and (min-width:500px) { … }
@media (min-width:500px) { … }

/* As are these: */

@media (orientation: portrait) { … }
@media all and (orientation: portrait) { … }

此外,还有以下媒体类型:' tty',' tv','投影','掌机',&#39 ;盲文','浮雕'听觉'已在Media Queries Level 4中弃用。

答案 1 :(得分:0)

所有是指:所有媒体类型设备,打印:用于打印,屏幕:用于桌面屏幕,手机,平板电脑等和演讲:用于屏幕阅读器"读取"页面响亮。

如果您将媒体类型指定为all,则可以尝试通过右键单击打印页面。打印的页面将简单地应用所有样式,它们看起来完全相同。

现在再举一个例子,将媒体类型指定为screen。如果您尝试打印页面,则不会看到所有样式都应用于页面,因为仅为屏幕定义了样式。

如果在媒体查询中未指定all,则默认情况下将其视为all



@media screen {
  div {
    color: blue;
  }
  .print{
    display: none;
  }
}

@media print and (min-width: 200px){
  div{
    color: tomato;
  }
  div.not('.example'){
    display:none !important;
  }
  .print{
    display: block;
  }
}

<div class="example">
  <div>Try printing me. See if this blue color appears while printing</div>
  <div class="print">I am only visible while printing.</div>
</div>  
  
&#13;
&#13;
&#13;

相关问题